查找域中的所有共享

Find all shares on a domain

是否可以使用 powershell 查找域上的所有网络共享?

我试过以下方法:

Get-WmiObject -class Win32_Share -ComputerName test1

可以运行 列出所有共享的脚本。它必须是 运行 在 Windows 服务器或安装了 Microsoft RSAT 的计算机上。

  1. 安装 RSAT(如果需要)。
  2. 在每台目标计算机上,运行 winrm quickconfig 允许远程 WMI 调用。
  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)