2017-09-28 5 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'를 이미 사용하고 있으므로'-ComputerName' 매개 변수를 사용하여'Invoke-Command'를 완전히 제거 할 수 있습니다. 여전히 작동할까요? –

+0

환상적입니다, 감사합니다. Get-WmiObject를 사용하면 많은 의미가 있습니다. 나는 그것이 작동하기 위해서는 서비스 실행과 방화벽 설정이 필요하다고 생각한다. 내가 일하게되면 게시 할 것이다 : – Fidel

+0

RPC 프로토콜은 필수 서비스이며 항상 켜져있다. 방화벽에는 TCP 포트 135가 필요할 수 있습니다. 표준 회사 네트워크에서는 모든 내부 서브넷에 대해 열려있을 수 있습니다. DMZ는 아마도 다른 이야기 일 수 있습니다. –