此代码的问题是,对于每个文件夹,我只获得1个组或1个用户,具体取决于文件夹(主要是最后一个),而我想获取所有安全组和文件夹的成员,驱动器中的每个文件夹。
$title = "ADPermissions.csv"
$title2 = "ADPermissions2.csv"
$ss =$Selection1 -replace '[\W]', ''
$subtitle = "HardDrive"+ $ss
$exclude = @("BUILTIN|NT AUTHORITY|EVERYONE|CREATOR OWNER|NT AUTHORITY\SYSTEM|SYSTEM")
$OutFile = ($Selection2+"\"+$subtitle+$title)
Write-Host = $OutFile
if(Test-Path $OutFile -PathType Leaf)
{
$result3 = [System.Windows.MessageBox]::Show("The file already exists in the selected path`n"+"Do you want to delete it and proceed ?",'File already exists','YesNoCancel','Exclamation')
if ($result3 = "Yes")
{
Remove-Item $OutFile
$Header = "Folder Path,IdentityReference,names"
$RootPath = $Selection
$Folders = dir $RootPath | where {$_.psiscontainer -eq $true}
#To the point:
try {
foreach ($Folder in $Folders){$ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access } | where {$_.identityreference -notmatch $exclude}
Foreach ($ACL in $ACLs){
$strAcls = $ACL.IdentityReference.ToString()
$strUsers=@()
$strNames=$strAcls.Remove(0,12)
$user = $(try {Get-ADUser $strNames} catch {$null})
if ($strNames -ne $null -and $user -eq $null) {
$A += Get-ADGroupMember -identity $strNames -Recursive | Get-ADUser -Property DisplayName | Select Name | Sort-Object Name
} else {
}
foreach ($env:USERNAME in $A){
$strUsers +=$env:USERNAME
}
$OutInfo = $Folder.fullname + "," + $ACL.IdentityReference + $strUsers
}
Add-Content -Value $OutInfo -Path $OutFile | sort-Object
}
}catch [System.IO.IOException] {
}
}
I:\ Dropbox,GESCOEUROPE \ GR_G-FCASB-INT-ALL @ {Name = CAPPUCCILLI FEDERICO} @ {Name = De Fruyt Frederik}
I:\一般来说,GESCOEUROPE \ GR_G-FCASB-INT-ADMIN @ {名称= CAPPUCCILLI FEDERICO} @ {Name = De Fruyt Frederik @ {Name = VANDEWALLE MARIA} @ {Name = VANSTEELANDT LUCRECE}
我:\ ICT,GESCOEUROPE \ GR_G-FCASB-INT-ADMIN @ {Name = CAPPUCCILLI FEDERICO} @ {Name = De Fruyt Frederik} @ {Name = FREDERIK DE FRUYT(ADM)} @ {Name = GAILITE ZANETE} @ {Name = Geldhof Francine} @ {Name = GOEMAERE GWENNY}
I:\ PaymentFollow-向上,GESCOEUROPE \ GR_G-FCASB-INT-ALL @ {名称= CAPPUCCILLI FEDERICO}
这是我得到的输出,正如您所看到的每个文件夹我只有1 group,但那不正确,因为有些文件夹有多个组