2017-09-28 3 views

答えて

0

すべての株式を一覧表示するスクリプトを実行することが可能です。 Windows ServerまたはMicrosoft RSATがインストールされているコンピュータで実行する必要があります。

  1. RSATをインストールします(必要な場合)。
  2. 各ターゲットコンピュータで、リモートWMI呼び出しを許可する場合はwinrm quickconfigを実行します。
  3. 次のpowershellスクリプトを実行します。

FindAllShares.ps1

#This must be run on a computer that has the ActiveDirectory module installed (eg. Windows Server) 
#The module can be installed using the RSAT suite from Microsoft. 
Import-Module ActiveDirectory 

#To connect to remote computers, the following needs to be run on them: 
#winrm quickconfig 

#Get all the computers on the domain 
$computers = Get-ADComputer -Filter {enabled -eq $true} | select DNSHostName, Name 

$skipComputers = @("COMPUTER1", "COMPUTER2") #This is a list of computers to not check 
$skipShares = @("ADMIN$", "IPC$") 
$allShares = @() 

#Loop through all of the computers and ask each for their shares 
foreach ($computer in $computers | sort Name) 
{ 
    #Write-Host $computer.DNSHostName 

    if ($skipComputers -contains $computer.Name) 
    { 
     #skip these computers 
    } else 
    { 
     #Write-Host $computer.Name 

     #Get the shares on this computer 
     $shares = Invoke-Command -Computer $computer.DNSHostName -ScriptBlock {Get-WmiObject -class Win32_Share} 

     foreach ($share in $shares) 
     { 
      #Write-Host $share.Name 

      if ($skipShares -contains $share.Name) 
      { 
       #skip these shares 
      } else 
      { 
       $sharePath = "\\$($computer.Name)\$($share.Name)" 
       #Write-Host $sharePath 

       $allShares += $sharePath 
      } 
     } 
    } 
} 

#Write-host $($allShares -join ";") 
Write-host $($allShares | Out-String) 
+1

私は正直に、あなたの発見を共有して感謝しています。このスクリプトでは、winrmがすべてのマシンで構成されていることを前提としています。また、設定することもできない場合もあります。 'Invoke-command'は、WinRMを設定する必要があります。 'Get-WmiObject'はしません。すでに 'Get-WmiObject'を使用しているので、' Invoke-Command'の使用を完全に排除するために '-ComputerName'パラメータを使用することができます。それでも動作するのでしょうか? –

+0

素晴らしい、ありがとうRohin。 Get-WmiObjectを使用することは非常に意味があります。私はそれも動作するためには、サービスを実行し、ファイアウォール設定が必要と信じています。私はそれが働くことを投稿します:) – Fidel

+0

それは不可欠なサービスであり、常にオンになっているRPCプロトコルを利用しています。ファイアウォールにはTCPポート135が必要な場合があります。標準の企業ネットワークでは、すべての内部サブネットに対してオープンになります。 DMZはおそらく別の話です。 –

関連する問題