Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Powershell script: Output file (results) to come out on same line

$
0
0

I have a powershell script that checks security permissions in folders and writes the outcome to a csv file. With mine at the moment its writing each new file to a new line so its coming out like this at the moment:

"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 want it to come out like this:

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

how do i amend my code to reflect this:

 
	$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}}}|% {$_ -replace '"', ""}|Export-Csv $OutFile -NoType -Force -Encoding ascii


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>