我已经有了下面的脚本,可以用于大多数文件和文件夹,但是对于带有 "[" "]" 的文件和文件夹无效。
#Set variables
$path = $args[0]
$filename = $args[1]
$date = Get-Date
#Place Headers on out-put file
$list = "Permissions for directories in: $Path"
$list | format-table | Out-File "C:\Powershell\Results\$filename"
$datelist = "Report Run Time: $date"
$datelist | format-table | Out-File -append "C:\Powershell\Results\$filename"
$spacelist = " "
$spacelist | format-table | Out-File -append "C:\Powershell\Results\$filename"
#Populate Folders Array
[Array] $folders = Get-ChildItem -path $path -force -recurse
#Process data in array
ForEach ($folder in [Array] $folders)
{
#Convert Powershell Provider Folder Path to standard folder path
$PSPath = (Convert-Path $folder.pspath)
$list = ("Path: $PSPath")
$list | format-table | Out-File -append "C:\Powershell\Results\$filename"
Get-Acl -path $PSPath | Format-List -property AccessToString | Out-File -append "C:\Powershell\Results\$filename"
"-----------------------" | Out-File -FilePath "C:\Powershell\Results\$filename" -Append
} #end ForEach