2

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?

2 Answers 2

6

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
Sign up to request clarification or add additional context in comments.

Comments

5

The thing you can do in your case is to run Export-CSV with the -Append flag including the first time

Your_Data_In_Pipe | Export-Csv Your_File.csv -Append -NoTypeInformation

If you really want to remove the first line of your CSV file you can use :

Get-Content Your_File.csv | select -Skip 1 | Set-Content Your_FileBis.csv

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.