我試圖列出所有可以訪問一個特定目錄和該目錄中的子檔案夾的用戶。
我發現這個網站可以很好地告訴我如何做到這一點。但是我想稍微修改一下這個腳本,這樣我就可以從輸出中排除某些內置的 Windows 用戶。
所以我在StackOverflow上找到了另一個鏈接,它顯示了如何從結果中排除一個用戶串列。但是當我將-notmatch添加到現有的PS腳本中時,Group/User從實際的用戶名變成了True或False,這是由于某些原因。
我怎么做才能讓這個腳本過濾掉$ignore變數中的用戶,并讓Group/User顯示用戶名呢?
$ignore = @('BUILTINAdministrators','CREATOR OWNER')
$ExcludeUsersRegex = ($ignore | % { [regex]::Escape($_) }) -join '|'/span>
$FolderPath = Get-ChildItem -Directory -Path "D:MSSQL" -Recurse -Force
$Output = @()
ForEach ($Folder in $FolderPath) {
$Acl = Get-Acc -Path $Folder.FullName
ForEach ($Access in $Acl.Access) {
$Properties = [ordered]@{'Folder Name'=$Folder。 FullName;'Group/User'=$Access. IdentityReference -notmatch $ExcludeUsersRegex;'Permissions'=$Access. FileSystemRights;'Inherited'=$Access.IsInherited}。
#$Properties = [ordered]@{'Folder Name'=$Folder.FullName; 'Group/User'=$Access.IdentityReference; 'Permissions'=$Access.FileSystemRights; 'Inherited'=$Access.IsInherited}
$Output = New-Object -TypeName PSObject -Property $Properties >。
}
}
$Output | Out-GridView
uj5u.com熱心網友回復:
你可以在回圈層面進行過濾,所以不受歡迎的用戶不會在回圈中被迭代。
ForEach($Access in ($Acl. Access|Where{$_.IdentityReference -notmatch $ExcludeUsersRegex}) {
這就過濾掉了與特定用戶名相匹配的訪問。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/309295.html
標籤:
上一篇:使用遞回創建一個倒計時|FreeCodeCamp遞回問題
下一篇:如何在AD中禁用組
