PSCommander
Command your desktop with PSCommander.
PSCommander is now free and open source.
PSCommander allows you to configure various Windows integration points and execute PowerShell script blocks when certain things happen on your desktop.
Features
CRON Schedules
Desktop Shortcuts
Events
Explorer Context Menu
File Associations
Global Hot Keys
Tray Icon and Menu
Installation
PSCommander is installed as a PowerShell module. You can install it from the PowerShell Gallery.
Once you have the module installed, you can cause PSCommander to run at logon by using the Install-Commander
cmdlet.
Licensing
PSCommander requires a PowerShell Pro Tools license. If you already have a license installed, you will be able to use PSCommander. You can also use the Install-CommanderLicense
cmdlet to install your license file.
Configuration
PSCommander is configured using a single PS1 file. This file is stored within your documents folder. To create a new config file, you can use the following command.
PSCommander will use this configuration file to load settings. Any changes to the file will result in PSCommander reconfiguring itself. If you don't have PSCommander running yet, you can use Start-Commander
.
The following sections outline the commands you can use within the config.ps1
file. These cmdlets will not work outside of PSCommander.
Features
CRON Schedules
PSCommander allows you to run script blocks based on CRON schedules. Note that PSCommander uses a single runspace. Long running scripts are not recommended for use with PSCommander.
To create a CRON schedule, use New-CommanderSchedule
within the config.ps1
file. For example, this configuration will create a schedule that opens notepad every minute.
You can use a site like crontab guru to define schedules.
Custom Protocol Handlers
A custom protocol handler can cause a PSCommander action to be taken from a website or other invocation of the custom protocol.
To define a custom protocol, you can use the New-CommanderCustomProtocol
. The $args[0]
parameter will have the URL that was clicked.
To use the custom protocol, you can include regular links in websites and it will invoke PSCommander remotely.
Data Sources
Data sources allow you to load data a single time and use it with multiple desktop widgets. This provides better performance than loading the data in each widget. It also provides data binding support for WPF components.
To register a data source, use the Register-CommanderDataSource
cmdlet. The below data source loads computer performance information. It loads the data every 5 seconds.
To use this data source with a desktop widget, you'll need to use the -DataSource
parameter for a custom widget. Every time the data source is updated, the WPF custom widget will be notified and will load UI components.
This example creates a small, grey bar that formats and displays the computer information.
The XAML can take advantage of binding to the hashtable created by the data source.
This produces a widget that looks like this.
Desktop Widgets
PSCommander providers a desktop widget system that allows you to place text, images, web pages, custom WPF windows and measurement counters on the desktop. It is a similar experience to SysInternals bginfo and Rainmeter.
All widgets are created using the New-CommanderDesktopWidget
cmdlet in combination with the New-CommanderDesktop
or Set-CommanderDesktop
cmdlets.
Text Widget
The following example creates a text widget with some computer information.
Image Widget
The following example creates an image widget on the desktop.
Webpage Widget
The following example creates a webpage widget on the desktop.
Custom WPF Widget
The following example creates a custom WPF widget on the desktop.
Measurement Widget
The following creates a measurement widget on the desktop.
Desktop Shortcuts
PSCommander can create desktop shortcuts that will execute PowerShell when clicked. Desktop shortcuts require the PSCommander is running so you may want to use Install-Commander
to ensure that it has been started before a user clicks a shortcut.
You can configure the text, description and icon for the shortcut. This example creates a desktop shortcut that opens notepad when clicked.
Events
PSCommander can register event handlers that invoke script blocks based on events happening within your system. You can use the Register-CommanderEvent
cmdlet to listen to these events.
The following example starts notepad when commander starts.
You can also listen to events that are happening with Windows using WMI event filters. This example will use the built-in ProcessStarted
event to run a script block whenever a process is started. This example writes to a file. The $args[0]
is the WMI object that was created.
If you want to configure a custom WMI event, you can use the -WmiEventType
and -WmiEventFilter
parameters to listen for those events.
Explorer Context Menus
PSCommander can create context menu items that appear when right clicking on folders and files within Windows Explorer. Your script block will receive the path to the folder or file via the $Args[0]
variable.
You can create context menu items that appear on folders or only apply to particular extensions of files.
This example creates a context menu that displays as Click Me and opens VS Code to the file that was clicked.
File Associations
PSCommander allows you to associate files with script blocks defined within the commander configuration. You can define the extension and action to take when the file type is open. You will receive the full file path in the $Args[0]
variable.
This example opens VS Code based on the file that was opened and associates it with the .ps2
file extension.
Global Hot Keys
PSCommander allows you to associate global hot keys to PowerShell actions.
This example defines a hot key that is invoked whenever the Ctrl+T
key combo is pressed. Note that key combinations cannot interfere with other pre-existing combinations.
Tray Icon and Menu
PSCommander provides configuration for the tray icon. You can define the hover text and the icon that is displayed. You can choose to hide the Exit and Edit Config options and define your own right click menus.
Tray menu items can invoke script actions and you can define menu items dynamically. This example creates some menu items statically and dynamically.
Last updated