I have a requirement to request some information that comes in the form of an object. I need to replace some test in one of the properties and then write the list of objects to CSV.
When I do
Get-Process | select * | %{ $_Path.Replace("chrome", "ie") }
I have two problems
- If $_.Path is null, it gives me an error that you cannot call a method on a null-valued expression
- The output is a single string representing the text that was replaced (just the Path property). I need the original object and all of it's properties kept, but with the updated path value.
So of course when I try to do
Get-Process | select * | %{ $_Path.Replace("chrome", "ie") } | Export-Csv -Path "out.csv"
What I get is a single property Length because the output of the above is a string with only the Length property.