I use the following line in my script to return all the paths of all folders at the $folder
location.
dir -recurse $folder|?{$_.PSIsContainer}|select -ExpandProperty FullName
This works. But: I only need the fourth element of each path.
I've tried adding |{$_.Split("\")}[3]}
with the [3]
in various places but I am getting an error with the split command, that Expressions are only allowed as the first element of a pipeline.
I've tried putting brackets around various sections, and putting the whole expression into brackets and into a split but I can't seem to find a way to attach the split to any part of the pipe... Is there another way, perhaps?
You are almost there. You need to put your code within the Foreach-Object
cmdlet:
Get-ChildItem -recurse $folder|
Where-Object {$_.PSIsContainer}|
Select-Object -ExpandProperty FullName |
ForEach-Object {
$_.Split("\")[3]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With