我正在尝试获取组和成员的权限,以列出所有详细的共享。 我找到了这个脚本。我正在尝试执行它,但是出了点问题。我希望它返回一个结果,该结果将在CSV文件中过滤,如下所示:
$queryPath = "s:\it\install"
$targetFile = "C:\Test.csv"
$Table = @()
$Record = [ordered]@{
"Path" = ""
"IdentityReference" = ""
"Class" = ""
"GrpMember" = ""
}
$foldersToQuery = Get-ChildItem $queryPath | Where {$_.PSIsContainer} | select -expandproperty FullName
foreach ($folder in $foldersToQuery) {
$Record.Path = $folder
$permissions = Get-Acl $folder | select -expandproperty Access
foreach ($permission in $permissions) { {
[string]$id = $permission.IdentityReference
$SamAccountName = $id.Split('\')[1]
$ADObject = Get-ADObject -Filter ('SamAccountName -eq "{0}"' -f $SamAccountName) }
$Record.IdentityReference = $permission.IdentityReference.ToString()
switch ($ADObject.ObjectClass) {
'user' {
$Record.Class = $ADObject.ObjectClass
$Record.GrpMember = ""
$objRecord = New-Object PSObject -property $Record
$Table += $objrecord
}
'group' { {
$Record.Class = $ADObject.ObjectClass
$members = Get-ADGroupMember $SamAccountName }
foreach ($member in $members) {{
$Record.GrpMember = $member.name
$objRecord = New-Object PSObject -property $Record
$Table += $objrecord
}
}
}
}
}
}
$Table | Export-Csv $targetFile -NoTypeInformation -Encoding UTF8