Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell Remove Column Headings

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?

like image 543
The Woo Avatar asked Jan 27 '26 05:01

The Woo


1 Answers

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
like image 196
LedHed Avatar answered Jan 31 '26 00:01

LedHed