I have the script below working for most of the files and folders but is not working for files and folders with "[" "]"
#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
I'm not sure this does 100% the same thing but I'm using the following one-liner
get-childitem "C:\windows\temp" -recurse | get-acl | Format-List | Out-File "c:\temp\output.txt"
The problem is with the Convert-Path
cmdlet trying to "interpret" the path including the square brackets which it "interprets" as wildcard characters. Instead you want to have it use the literal path.
Change this line:
$PSPath = (Convert-Path $folder.pspath)
To this:
$PSPath = (Convert-Path -LiteralPath $folder.pspath)
Also, change the Get-Acl -path
to Get-Acl -LiteralPath
so it looks like this:
Get-Acl -LiteralPath $PSPath | Format-List -property AccessToString | Out-File -append "C:\Powershell\Results\$filename"
If you don't have PowerShell Version 3.0 (where Get-Acl added -LiteralPath support), you can use Get-Item as a workaround:
$item = Get-Item -LiteralPath $PSPath
$item.GetAccessControl() | Format-List -property AccessToString | Out-File -append "C:\Powershell\Results\$filename"
For more information see this article: LiteralPaths
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With