需要一些帮助来编写 powershell 脚本来枚举组织中所有打开的文件共享及其共享权限。到目前为止,我已经尝试了以下方法,但面临共享权限的问题
$ComputersNames = Get-ADComputer -Filter * | select Name
$FileShares = New-Object "System.Collections.Generic.List[string]"
foreach ($ComputerName in '$ComputersNames')
{
try
{
$connected = (Test-Connection -BufferSize 32 -Count 1 -ComputerName $ComputerName -Quiet -ErrorAction Ignore)
if ($connected)
{
$Shares = net view \\$ComputerName /all 2>&1 | select-object -Skip 7 | ?{$_ -match 'disk*'} | %{$_ -match '^(.+?)\s+Disk*'|out-null;$matches[1]}
foreach ($Share in $Shares)
{
$line = "\\$ComputerName\$Share"
$FileShares.Add($line)
我知道要列出开放共享的共享权限,我必须使用类似的东西,但不知道如何在脚本中使用它来枚举所有计算机的所有开放共享
Invoke-Command -ComputerName **** -ScriptBlock {Get-SmbShare } | Select -ExpandProperty PresetPathAcl
尝试以下。 您可以向 $newRow 添加任意数量的属性
$ComputersNames = Get-ADComputer -Filter * | select Name
$FileShares = [System.Collections.Generic.List[pscustomobject]]::new()
foreach ($ComputerName in '$ComputersNames')
{
$newRow = New-Object -TypeName psobject
try
{
$connected = (Test-Connection -BufferSize 32 -Count 1 -ComputerName $ComputerName -Quiet -ErrorAction Ignore)
if ($connected)
{
$Shares = net view \\$ComputerName /all 2>&1 | select-object -Skip 7 | ?{$_ -match 'disk*'} | %{$_ -match '^(.+?)\s+Disk*'|out-null;$matches[1]}
foreach ($Share in $Shares)
{
$newRow | Add-Member -NotePropertyName 'Computer Name' -NotePropertyValue "\\$ComputerName\$Share"
}
}
}
$table.Add($newRow) | Out-Null
}