New
#31
It can only reopen filesystem locations. Virtual folders such as This PC , Quick Access, and Libraries don't have a LocationURL value.
Open some Explorer windows & check the ouput of this command:
Code:$Shell.Windows() | select LocationName, LocationURL
Keith,
I get the response
Code:PS C:\> $Shell.Windows() | select LocationName, LocationURL You cannot call a method on a null-valued expression. At line:1 char:1 + $Shell.Windows() | select LocationName, LocationURL + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
I take it you meant for it to be inserted within the original script?
Denis
Keith,
Thanks.
I've been playing around with the code and am a bit baffled by its behaviour. Sometimes it captures my open IE windows and sometimes it does not.
I tested it by altering it a bitso I could see what it was picking up instead of going through the whole procedure every time.Code:$Shell = New-Object -ComObject shell.application $SavedPaths = ( $Shell.Windows() | select LocationName, LocationURL ) -ne '' #####Get-Process explorer | Stop-Process #####$SavedPaths | ForEach { explorer $_ } $SavedPaths | ForEach { echo $_ } | export-csv "D:\Desktop\ExplorerProcessList.csv" -append -NoTypeInformation pause
The inclusion or omission of IE windows is not critical behaviour but the inconsistency is a puzzle [to me].
Denis
Not sure about the IE window behavior, but if I may....
- You can drop the
-ne ''
from:
$SavedPaths = ( $Shell.Windows() | select LocationName, LocationURL ) -ne ''
In the original code, it filtered out empty strings that were returned by virtual folders from the array of strings created by expanding LocationURL. You're now creating a custom object that will never match an empty string.$SavedPaths | ForEach { echo $_ } | export-csv "D:\Desktop\ExplorerProcessList.csv"...
can be simplified to:
$SavedPaths | export-csv "D:\Desktop\ExplorerProcessList.csv"
ive tried a few times and unlike try3 i have had no success. I opened up several folders (not My Computer type, but c drive, system 32, d drive etc) and they all show and list under
Code:$Shell.Windows()|selectLocationName,LocationURL
but with original code they just dont get restored upon process restart. what could be the cause?
$Shell = New-Object -ComObject shell.application
$SavedPaths = ( $Shell.Windows() | select -expand LocationURL )
Get-Process explorer | Stop-Process
$SavedPaths | ForEach { explorer $_ }
This is of no help to you at all but I've compared what you are using with what I'm using and they are exactly the same.
RestartExplorerWithFolders.ps1
Code:$Shell = New-Object -ComObject shell.application $SavedPaths = ( $Shell.Windows() | select -expand LocationURL ) Get-Process explorer | Stop-Process $SavedPaths | ForEach { explorer $_ }
I have also run them by pasting those commands into a PowerShell window - as shown, there are no error responses.
Code:PS C:\Users\Denis> $Shell = New-Object -ComObject shell.application PS C:\Users\Denis> $SavedPaths = ( $Shell.Windows() | select -expand LocationURL ) PS C:\Users\Denis> Get-Process explorer | Stop-Process PS C:\Users\Denis> $SavedPaths | ForEach { explorer $_ } PS C:\Users\Denis>
As you noted above, it works for me [both as a ps1 file & as a set of commands in the PS window]. My FE folders get reopened afterwards
Denis