I have the following code that exports to a CSV file the folder permissions from a root path:
$RootPath = "\\R9N2WRN\Test Folder"
$OutFile = "C:\CodeOutput\Permissions.csv"
$Header = "Folder Path,IdentityReference"
Del $OutFile
Add-Content -Value $Header -Path $OutFile
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
foreach ($Folder in $Folders)
{
$ACLs = get-acl $Folder.fullname |
ForEach-Object { $_.Access } |
Where {$_.IdentityReference -notlike "*BUILTIN*" -and $_.IdentityReference -notlike "*NT AUTHORITY*"}
Foreach ($ACL in $ACLs)
{
$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference
Add-Content -Value $OutInfo -Path $OutFile
}
}
The output file has the column headings "Folder Path" and "IdentityReference", and as I want to run this script on multiple root paths, is there a way to get rid of those column headings from being sent with the output to CSV file?
I know this is an old post and has been answered, but thought this might be helpful for others.
I was looking to do something similar, but didn't want to write the output to file, read, then re-write. So I did this instead:
Your_Data_In_Pipe | ConvertTo-Csv -NoTypeInformation | select -Skip 1 | Set-Content File_Without_Headers.csv
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