我試圖使用Get-ACL
函數來掃描目錄中的子文件夾。我正在修改我在這裏找到的工作腳本,將輸出轉換爲.csv
文件。如果我可以得到輸出,那麼將會很好,因此每個文件夾的每行都包含全部IdentityReference
值。但是我最好的嘗試導致與此錯誤:格式化Get-ACL輸出
Method invocation failed because [System.Security.Principal.NTAccount] does not contain a method named 'op_Addition'.
下面是代碼:
$OutFile = "C:\Admin\Permissions.csv"
$Header = "FolderPath,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
Del $OutFile
Add-Content -Value $Header -Path $OutFile
$RootPath = "I:\Users\ES"
$Folders = GCI $RootPath\* | where {$_.psiscontainer -eq $true}
foreach ($Folder in $Folders){
$ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access }
Foreach ($ACL in $ACLs){
$OutIR = $ACL.IdentityReference
$OutIR += ","
}
$OutInfo = $Folder.Fullname + "," + $OutIR + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
Add-Content -Value $OutInfo -Path $OutFile
}
我試圖用變量$OutIR
趕在年底全部IdentityReferences
,然後添加$OutIR
的結果。每個文件夾將被列出並在同一行上,所有IdentityReference
將被顯示。
已更新>非常感謝所有幫助到目前爲止!兩個代碼都可以工作(真棒!),但我真的很想調整輸出。順便說一句,這是我第一次在這裏尋求幫助,它真的讓真正的腳本編寫者看着這個!
我在Windows 2012 R2機器上使用Powershell 4.0。
我得到了輸出的一個例子是:
"I:\Users\ES\aalvarez","NT AUTHORITY\SYSTEM","Allow","False","ContainerInherit, ObjectInherit","None"
"I:\Users\ES\aalvarez","BUILTIN\Administrators","Allow","False","ContainerInherit, ObjectInherit","None"
"I:\Users\ES\aalvarez","XXX\aralvare","Allow","False","ContainerInherit, ObjectInherit","None"
我想有輸出是:
"I:\Users\ES\aalvarez","NT AUTHORITY\SYSTEM","BUILTIN\Administrators","XXX\aralvare","Allow","False","ContainerInherit, ObjectInherit","None"
的想法是,我可以把我的1000+用戶在電子表格中快速比較文件夾ACL。再次感謝!
嘗試所有的輸出變量轉換爲字符串,即'$ Folder.Fullname.ToString()' – slybloty
什麼版本的PowerShell您使用? – mjolinor
你能提供一個你想要輸出看起來像什麼的例子嗎? – mjolinor