You probably know that PowerShell supports alias names for commands. But did you know that you can define alias names for PowerShell functions...
powertips
Checking Operating System Version
Here is a simple and fast way of checking the operating system version: PS C:\> [Environment]::OSVersion Platform ServicePack Version...
Comparing Against $NULL
If you want to find out whether a variable contains $Null (nothing), always make sure you keep $null on the left side of the comparison. Most of the...
Examining Certificate Details
If you’d like to examine and view the details of a certificate file without the need to import it into your certificate store, here is a...
Exporting ActiveDirectory Module
To manage users and computers in your Active Directory from PowerShell, you need the ActiveDirectory module which comes as part of the free RSAT...
Managing NTFS Permissions
While there are not many built-in cmdlets to manage NTFS permissions, there is a growing list of open source PowerShell modules adding these. One...
Determine if Array Contains Value – Using Wildcards
If you’d like to know whether an array contains a given element, PowerShell provides the –contains operator. This operator does not...
Working with LDAP and Dates
LDAP filters are a fast and powerful way of retrieving information from Active Directory. However, LDAP filters use a very low-level date and time...
Using a PowerShell Parameter Validator
PowerShell function parameters support a ValidateScript attribute where you can assign PowerShell code. The code is invoked when the parameter...
Casting Data with Culture
When casting data (converting it to a different data type), PowerShell supports two approaches that can differ considerably. Here is an example:...
Invoking a Script Block
Code inside a script block can either be invoked by call operators such as „&“ or „.“, or by calling the Invoke()...
Running Cmdlets without Verb
This has been part of PowerShell since version 1.0: cmdlets with verb „get“ can be invoked without the verb. So instead of...
Texts with Maximum Length (Part 2)
Here is another strategy to make sure a text does not exceed a given length. In contrast to our previous tip, this code will not pad spaces in case...
Texts with Maximum Length (Part 1)
If you want to make sure a text is of given length, here is an easy approach: $text = 'this is a long text' $MaxLength = 10...
Finding All Profiles with Desktop
This simple line dumps all paths to all desktops found in any of the local user profiles – just make sure you are running the line with...
Where-Object and .Where()
Beginning in PowerShell 4, you can use the Where() and Foreach() methods in place of Where-Object and ForEach-Object whenever you do not want to use...
Creating Object Arrays on the Fly
Here is a quick code sample that generates an array of objects using the built-in CSV parser: $csv = @' PC,Date PC82012,2017-02-28...
Exploring Type Accelerators
PowerShell uses a number of so-called type accelerators that help with long .NET type names. Instead of using...
Dangerous Temp Files!
Internal system functions are often helpful, but always make sure you fully understand what they do. A particularly popular system method is called...
Explore Objects
In PowerShell, anything is represented by objects, and here is a helpful one-liner that examines any object and copies its members as text into your...
Managing Bit Flags (Part 4)
In PowerShell 5, the new support for enums makes dealing with bit values much easier as you’ve seen in previous tips. Even setting or clearing...
Managing Bit Flags (Part 3)
Setting or clearing bit flags in a decimal is not particular hard but unintuitive. Here is a quick refresher showing how you can set and clear...
Managing Bit Flags (Part 2)
In the previous tip we illustrated how you can use PowerShell 5’s new enums to easily decipher bit flags, and even test for individual flags....
Managing Bit Flags (Part 1)
Occasionally, you might have to deal with bit flag values. Each bit in a number represents a certain setting, and your code might need to determine...