2

I run the following command to get a very basic audit of file permissions in PS:

Get-ChildItem -Directory E:\*,E:\*\*,E:\*\*\* | 
Get-Acl | Format-list Path,AccessToString | 
Out-File -Filepath c:\myfile.txt

The output of Format-List contains info in the path I want to strip out, namely Microsoft.PowerShell.Core\FileSystem::

But if I add {$_ -replace "Microsoft.PowerShell.Core\FileSystem::",""} before the output file pipe I get errors.

Is there a way to parse out this data through a piped output, or do I have to create a function?

2 Answers 2

3

You could inline replace the contents of Format-List using a calculated property like this

@{Label="Path"; Expression={$_.path.Replace("Microsoft.PowerShell.Core\FileSystem::", "")}}

Your command then becomes

Get-ChildItem -Directory C:\* |
Get-acl |
Format-List @{Label="Path"; Expression={$_.path.Replace("Microsoft.PowerShell.Core\FileSystem::", "")}}, accesstostring |
Out-File -filepath c:\myfile.txt
Sign up to request clarification or add additional context in comments.

1 Comment

That worked great, can you give me a breakdown? This will be really useful in other situations but I think Avshalom's answer was more concise. This was very helpful, though, thanks!
2

You can use Convert-Path

Get-ChildItem -Directory C:\*,C:\*\*,C:\*\*\* | 
Get-Acl | Format-list @{N="Path";E={Convert-Path $_.Path}},AccessToString | 
Out-File -Filepath c:\myfile.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.