我只想知道服务器上的所有共享,或更好的域中的所有共享。 我希望可以通过PowerShell脚本。
如果您想要从域中的所有计算机上共享资源,则可以使用Get-WmiObject来查询每台计算机上的Win32_Share wmi类:
# Import the AD module to the session Import-Module ActiveDirectory # Retrieve the dNSHostName attribute from all computer accounts in AD $ComputerNames = Get-ADComputer -Filter * -Properties dNSHostName |Select-Object -ExpandProperty dNSHostName $AllComputerShares = @() foreach($Computer in $ComputerNames) { try{ $Shares = Get-WmiObject -ComputerName $Computer -Class Win32_Share -ErrorAction Stop $AllComputerShares += $Shares } catch{ Write-Error "Failed to connect retrieve Shares from $Computer" } } # Select the computername and the name, path and comment of the share and Export $AllComputerShares |Select-Object -Property PSComputerName,Name,Path,Description |Export-Csv -Path C:\Where\Ever\You\Like.csv -NoTypeInformation
使用PowerShell,您可以使用Get-SMBShare 。
如果您的操作系统版本与此cmdlet不兼容,则可以使用旧版net share 。
至于如何在每个服务器上运行它,可以在命令提示符中使用PowerShell中的Invoke-Command或Sysinternals中的psexec 。