header image

COM pt 2–More Shell

Posted by: | January 24, 2011 | No Comment |

$shell = New-Object -ComObject "Shell.Application"

gets us a shell object.  We can then see the methods available to us


PS> $shell | gm -MemberType method | Format-Wide -Column 2

AddToRecent           BrowseForFolder
CanStartStopService   CascadeWindows
ControlPanelItem      EjectPC
Explore               ExplorerPolicy
FileRun               FindComputer
FindFiles             FindPrinter
GetSetting            GetSystemInformation
Help                  IsRestricted
IsServiceRunning      MinimizeAll
NameSpace             Open
RefreshMenu           ServiceStart
ServiceStop           SetTime
ShellExecute          ShowBrowserBar
ShutdownWindows       Suspend
TileHorizontally      TileVertically
ToggleDesktop         TrayProperties
UndoMinimizeALL       Windows
WindowsSecurity       WindowSwitcher



Are fairly obvious in what they do.


will also minimise all open windows. but it isn’t reversed by UndoMinimizeAll().


may cause some confusion as it represents a collection of all of the open windows that belong to the Shell. It does not show open all open Windows.

$shell.Windows() | select name, type, statustext

return these windows

Windows Internet Explorer
Windows Internet Explorer
Windows Internet Explorer
Windows Internet Explorer
Windows Explorer

Which is right for the shell.  I have IE open with 4 active tabs and Windows Explorer. What this doesn’t show is that I also have PowerShell, MSDN library, LiveWriter and LiveMail open. 

The lesson is to be careful and read the documentation.


could be useful for instance


will open Windows Explorer pointing at the scripts folder.

under: COM, PowerShellV2