Reputation: 21
This is based on another question: https://stackoverflow.com/a/9675811/14529561.
How would I pass the result from gci path | sort LastWriteTime | select -last 1
and open with explorer.exe?
I have tried:
$wd = gci path | sort LastWriteTime | select -last 1;
explorer $wd
gci path | sort LastWriteTime | select -last 1 | Format-Table -hidetableheaders | explorer $_.
gci path | sort LastWriteTime | select -last 1 | Format-Table -hidetableheaders | ii $_.
Unfortunately, all the above give me give me errors.
Upvotes: 2
Views: 337
Reputation: 8878
You can reference the PSParentPath
property.
Get-ChildItem -Path path |
Sort-Object -Property LastWriteTime |
Select-Object -Last 1 | Foreach-Object {
Invoke-Item $_.psparentpath
}
Upvotes: 1
Reputation: 18857
You can do it like this :
$Mypath=$Env:Temp
gci $Mypath | sort LastWriteTime | select -last 1 | % { Explorer /n,/select,$_.FullName }
And if you want to explore in more than folder, you can put thel into an array and do like this :
cls
$Mypath=@("$Env:UserProfile\desktop","$Env:Temp","$Env:AppData")
ForEach ($P in $Mypath) {
gci $P | sort LastWriteTime | select -last 1 | % { Explorer /n,/select,$_.FullName }
}
Upvotes: 0