PowerShell can access all public .NET classes, so it is (fairly) easy to create a message box: $result = [System.Windows.MessageBox]::Show('Do...
ps1
Using a Stopwatch to Profile Scripts
Ever wanted to find out how long a particular command or portion of your script took to complete? Here is a simple Stopwatch object that can help...
Color Week: Using Token Colors in the PowerShell Console
PowerShell 3 or better This week we are looking at how you can change coloring both in the PowerShell console and PowerShell ISE so you can fine...
Color Week: Changing Error Message Colors in the PowerShell ISE
This week we are looking at how you can change coloring both in the PowerShell console and PowerShell ISE so you can fine tune your PowerShell...
Saving PowerShell User Defaults
We are about to enter “Color Week” with plenty of tips how you can choose better colors for the PowerShell ISE editor and the console....
Finding ASCII Codes
Here is an easy way to find the ASCII code for any character you may have scraped from a website, or found in a script that you copied from the...
Checking Hard Drive Size (Local and Remote)
WMI can provide the raw data about hard drive size and free space. PowerShell then takes that information and provides user-friendly results like...
Enabling Remote Administration
PowerShell 2+ Many older DCOM-based commands require a “Remote Administration Firewall Exception” to access remote systems. This...
Finding Auto Starts
PowerShell 3+ If you’d like to know which programs start automatically on your machine, WMI may help: PS C:\> Get-CimInstance -ClassName...
Replacing CSV File Headers
PowerShell 2+ When you read in CSV data and would like to rename the CSV headers, here is a simple approach: just read in the text line by line, and...
Receiving Input via Pipeline
In the previous tip we illustrated how Convert-Umlaut was able to convert special characters in a string. This becomes even more useful if a...
Replacing Special Chars like “Umlauts”
PowerShell 2+ Sometimes it becomes necessary to replace special characters like German “Umlauts” in order to normalize user names or...
Using Friendly Robocopy
PowerShell 2+ Robocopy is a tool of choice to copy files, and that does not change with PowerShell. You can, however, use PowerShell to embed...
Beware of Changes to PSModulePath
PowerShell 3+ PowerShell examines the $env:PSModulePath environment variable to find out the locations where it searches for extension modules. A...
The Truth About WinRM
PowerShell 3+ The popular winrm command to manage and configure PowerShell Remoting is really just a batch and a VBS file: PS> Get-Command winrm...
Listening to Music in the Background
PowerShell 3+ In the previous tip we presented to you a “Dancing Rick ASCII”, created by Lee Holmes. Lee uses music stored on his server...
Smuggling In PowerShell Code
PowerShell 2 There is a good reason why Invoke-Expression is considered risky. This cmdlet executes whatever string it gets, and attackers can...
Display Windows
PowerShell 3+ It is fairly easy to use WPF (Windows Presentation Foundation) to create and show simple dialog windows in PowerShell. If you’d...
Add a Clock to PowerShell
PowerShell 2+ Here is a fun example that illustrates how to work with timers. It adds a clock to the title bar of the PowerShell console or the...
Changing Page File Location
PowerShell 2+ To move the Windows page file to a new location, you can use WMI: #requires -Version 2 $args = @{ Name = "D:\pagefile.sys" InitialSize...
Encrypting and Decrypting Secret Strings
When there is the need to encrypt sensitive data, scripts always face the challenge to protect the secret key used to decrypt. If the secret is to...
Finding Groups of Logged On User
If you’d like to know the group memberships of the currently logged on user (the one that is running a script), you don’t need to query...
Creating Dynamic Variable Content
PowerShell 2+ In the previous tip we introduced variables with read-only dynamic content that updated each time the variable was read. This required...
Creating Dynamic Variable Content
PowerShell 2+ A little-known fact is that you can add variables to PowerShell that automatically update their content. If you need random numbers,...