COM pt 2–More Shell
$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
$shell.MinimizeAll()
$shell.UndoMinimizeAll()
Are fairly obvious in what they do.
$shell.Toggledesktop()
will also minimise all open windows. but it isn’t reversed by UndoMinimizeAll().
$shell.Windows()
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.
$shell.Explore("folder-name")
could be useful for instance
$shell.Explore("c:\scripts")
will open Windows Explorer pointing at the scripts folder.