#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.

$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.

About the author: Jaap Brasser

Jaap is a Senior System Engineer in the Financial Services industry. He focuses on Microsoft and related technologies and has a passion for PowerShell. In his spare time he maintains his Blog, Twitter feed, @Jaap_Brasser, and contributes on the Official Scripting Guys Forum and Windows PowerShell TechNet forums

Related Posts