#PSTip Use Shell.Application to determine which folder is open in File Explorer

By using the Windows() method and the LocationURL and LocationName properties we can programmatically determine which folder is open in File Explorer.

1
2
3
$ShellApp = New-Object -ComObject Shell.Application
$ShellApp.Windows() | Where-Object {$_.Name -eq 'File Explorer'} | 
Select-Object LocationName,LocationURL

The Where-Object statement is required to filter out results from Internet Explorer. If you are interested in all results including the open Internet Explorer windows and tabs the Where-Object statement can be omitted.

Share on: