PowerShell features the ".." operator which produces lists of numbers. With the -join operator, you can convert these to almost anything...
ps1
Checking for AC Power
Ask WMI to find out whether your notebook is connected to AC: #requires -Version 1 $battery = Get-WmiObject -Class Win32_Battery | Select-Object...
Creating Enumerations
PowerShell 5.0 added the capabilities to define enumerations but in older PowerShell versions, you can create enumerations too, simply by compiling...
Crazy Prompt Function
The built-in "prompt" function is invoked whenever PowerShell completed interactive input, and you can use it to change the way your...
Conversation with PowerShell
Today's tip is using the programmable CommandNotFoundHandler to have PowerShell talk with you once you enter an unknown command:...
Finding Operating System Version
One of the easiest ways of getting your operating system version is this one line of code: PS> [Environment]::OSVersion Platform ServicePack...
Why Some Errors Aren't Caught
When you receive a red error message from PowerShell, you can always encapsulate the code in a try…catch block and handle the error yourself:...
Using Paths in Prompts
The default PowerShell prompt displays the current location. When you are deep inside nested folders, this steals room for your actual input, and...
Help Make PowerShell a Better Place!
Rather than ranting about things that don't work as expected, or things you feel are missing, be constructive! The PowerShell team takes great...
Try CTRL+SPACE!
In the PowerShell ISE, there are two key shortcuts that can help you. Pressing TAB works just like in the console, and each time you press TAB, you...
Adding Command Not Found Handler
Whenever PowerShell comes across a command name that it does not know, you see a red error message. However, starting with PowerShell 3.0, there is...
Auto-CaseCorrecting PowerShell Code
Often when you write PowerShell scripts, you may not have used the correct casing, used only partial parameter names, or used aliases instead of...
Finding Loaded Assemblies
To dump all .NET assemblies that are loaded in a PowerShell session, try this: System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object...
Finding Cmdlet Parameter Aliases
PowerShell cmdlets and functions can have parameters, and these parameters can have (shorter) alias names. One prominent example is the...
Simplify Parameter Attributes
If all of your systems run PowerShell 3.0 or better, you can start shortening function parameter attributes. Boolean attributes now all default to...
Why GetTempFileName() is Evil
Some may have come across a .NET call that is supposed to generate random temporary file names: $path = [System.IO.Path]::GetTempFileName() $path...
Creating Encoded PowerShell Commands on the Fly
When you run PowerShell code outside a PowerShell console, you need to submit the code to powershell.exe. To make sure your code does not conflict...
Adding ValidateRange to a Variable
If you'd like to apply a numeric range of legal values to a variable, you can add a ValidateRange attribute to the variable, pretty much like...
Why $MaximumHistoryCount has a Limit
If you try and increase your maximum command history, you may run into some limitations: PS C:\> $MaximumHistoryCount = 100000 The variable...
Increase History Cache
Command history can be a great help when you work for a while in a PowerShell session. Each session stores the commands you issued, and you can...
Getting Last Bootup Time
In PowerShell 3.0 and better, it's trivial to get back real DateTime information from WMI using Get-CimInstance. This would tell you when your...
Copying Arrays (Part 2)
In a previous tip we explained how you can safely "clone" an array using Clone() method. This will copy the content of an array to a new...
Copying Arrays (Part 1)
When you copy variable content, you may just copy the "reference" (memory address), not the content. Take a look at this example: $a =...
Using Encoded Scripts
In VBScript there were encoded scripts. Encoding is by no means a safe way of hiding script content, but it makes it a little harder for users to...