PowerShell Get Folders Permissions


  1. 說明
  2. 相關連結
  3. 參考資料

筆記如何使用 PowerShell 取得 Windows 作業系統下,資料夾目錄、檔案以及子資料夾的權限設定,對於盤查 File Server 的資料夾安全性而言非常方便。

logo

說明

參考 netwrix How to Export Folder Permissions to Excel or CSV File 所分享的 PowerShell Script,使用 PowerShell ISE 來迭代資料夾的權限,並且匯出為 CSV 格式檔案。

$SourcePath = "\\sdwh\folders"
$OutputPath = "C:\temp\folders.csv"
$FolderPath = dir -Directory -Path $SourcePath -Recurse -Force
$Report = @()

Foreach ($Folder in $FolderPath) 
{
    $Acl = Get-Acl -Path $Folder.FullName
    foreach ($Access in $acl.Access)
    {
        $Properties = [ordered]@{
            'Folder' = $Folder.FullName;
            'AD User/Group' = $Access.IdentityReference;
            'Permissions' = $Access.FileSystemRights;
            'Inherited' = $Access.IsInherited
        }
        $Report += New-Object -TypeName PSObject -Property $Properties
    }
}
$Report | Export-Csv -path $OutputPath -notype

相關連結

PowerShell 使用者不能錯過的 5 個技巧

Powershell 使用物件與資料結構 (Array, Hash)

PowerShell 常用指令筆記

參考資料

MSDocs - Invoke-WebRequest