Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Powershell csv output (content)restructuring

$
0
0

I am trying to change the output of my csv file, at the moment the content is coming out as each new line is being outputted on a new line as well so as below:

NT AUTHORITY\SYSTEM,"Allow FullControl,  (Inherited)",C:\Users\munjanga\Documents\Operations Orchestration\Central

BUILTIN\Administrators,"Allow FullControl,  (Inherited)",C:\Users\munjanga\Documents\Operations Orchestration\Central

But I dont want it to write the content like that instead write it like this(its showing both these lines on the same line in the text file):

UKAONBZ\Consulting_APP_SupportAllow  Modify, this folder, subfolders and files\\UKSHEFAP08\e$\Data\Global\PHE test cases\back up of phe\Test cases\Benefit statements

UKAONBZ\Consulting_APP_SupportAllow  Modify, this folder, subfolders and files (Inherited)\\UKSHEFAP08\e$\Data\Global\PHE test cases\back up of phe\Test cases\Benefit statements

My code is below, can someone help me restructure is please, I don't even know if it an append i need as i already have one:

$OutFile = "C:\Users\munjanga\Documents\AoN Project\Execute\$([Environment]::MachineName).txt"

$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"

Del $OutFile

Add-Content -Value $Header -Path $OutFile 

 

$RootPath = "C:\Users\munjanga\Documents\Operations Orchestration"

 

$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}

 

$isInherited = @{

  $true  = 'Inherited'

  $false = 'Not Inherited'

}

 

$inheritance = @{

  0 = 'files only'

  1 = 'this folder and subfolders'

  2 = 'this folder and files'

 3 = 'subfolders and files'

}

 

$fldr = $Folder.FullName

 

$Folders | % {

 $fldr = $_.FullName

Get-Acl $fldr | select -Expand Access |

  select @{n='Account';e={$_.IdentityReference}},

         @{n='Ace String';e={"{0} {1}, {2} ({3})" -f $_.AccessControlType,

           $_.FileSystemRights, $inheritance[$_.InheritanceFlags],

           $isInherited[$_.IsInherited]}},

         @{n='Object Path';e={$fldr}} | ConvertTo-Csv -NoTypeInformation | % {$_ -replace '"', ""} | Out-File $OutFile -Force -Encoding ascii -Append}


Viewing all articles
Browse latest Browse all 6937

Trending Articles