All PowerShell Versions Windows logs all shutdown events in its System event log. From there, you can extract and analyze the information. Here is a...
powertips
Searching Files with Regular Expressions
All PowerShell versions Get-ChildItem does not support advanced file filtering. While you can use simple wildcards, you cannot use regular...
Getting Files with Specific Extensions Only
All PowerShell versions When you use Get-ChildItem to get a list of files, you may have noticed that the -Filter parameter occasionally returns more...
Correcting ISE Encoding
All PowerShell versions When you run a console application inside the ISE editor, non-standard characters such as “ä” or...
Using the OpenFile Dialog
PowerShell 3.0 and newer Here’s a quick function that works both in the ISE editor and the PowerShell console in PowerShell 3.0 and above):...
Use Group-Object to Create Hash Tables
All PowerShell versions Group-Object can pile objects up, putting objects with the same property together in one pile. This can be quite useful,...
Have PowerShell Cheer You Up!
All PowerShell versions Writing PowerShell code is fun but can be frustrating at times. Here’s a function that makes PowerShell cheer you up....
Logging What a Script Does
All PowerShell versions You probably know that in a PowerShell console (not the ISE editor), you can turn on logging: PS> Start-Transcript This...
A Fun Beeping Prompt
All PowerShell versions If your computer has a sound card, here is a code snippet that will drive your colleagues nuts: function prompt { 1..3 |...
Returning More Than One Value
All PowerShell versions If a PowerShell function needs to return more than one value, best practice is to return objects, and store the information...
Edit Network “hosts” File
All PowerShell versions If you find yourself editing the “hosts” file regularly, then it may be tedious to manually open the file in an...
Watch Out With UNC Paths!
All PowerShell versions Many cmdlets can deal with UNC paths, but using UNC paths can produce flaky scripts. Take a look at this: PS> Test-Path...
Finding AD Users
All PowerShell versions Searching the AD can be done with simple calls provided you are logged on an Active Directory domain. In a previous tip we...
Finding and Dumping Registry Key Paths
All PowerShell versions In a previous tip we illustrated how to convert an internal PowerShell path format to a real path. Here is a use case. This...
Correcting PowerShell Paths
All PowerShell versions Occasionally, you might stumble across strange path formats like this one:...
Case-Correct Name Lists
All PowerShell versions Let’s assume it’s your job to update a list of names. Here is an approach that will make sure that only first letter in a...
Hibernate System
All PowerShell versions Here is a simple system call that will hibernate a system (provided of course that hibernation is enabled): function...
Recursing a Given Depth
PowerShell 3.0 and newer When you use Get-ChildItem to list folder content, you can add the –Recurse parameter to dive into all subfolders....
Managing Printers Low-Level
All PowerShell versions Recent Windows operating systems like Windows 8 and Server 2012 come with great printing support, but if you run older...
Aliases Can Be Dangerous
All PowerShell versions Aliases enjoy the highest priority among executable commands in PowerShell, so if you have ambiguous commands, PowerShell...
Converting Special Characters, Part 2
All PowerShell versions In a previous tip we illustrated how you can replace special characters in a text. Here is another approach that may be a...
Converting Special Characters, Part 1
All PowerShell versions Sometimes it becomes necessary to replace special characters with other characters. Here is a simple function that does the...
Test-Driving Scripts without Aliases
All PowerShell versions Aliases can be cool in interactive PowerShell but should not be used in scripts. In scripts, use the underlying commands (so...
Delete Aliases
All PowerShell versions While you can easily create new aliases with New-Alias or Set-Alias, there is no cmdlet to delete aliases. PS> Set-Alias...