This has been part of PowerShell since version 1.0: cmdlets with verb „get“ can be invoked without the verb. So instead of...
Powershell
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...
Working With Generics
Generic types can use placeholders for actual types, and you may be wondering why that can be exciting. There are a number of data types, for...
Inheriting Classes in PowerShell 5 (part 2)
Here is another use case for the new class feature in PowerShell 5. In the previous example, we illustrated how you can derive new classes from...
Inheriting Classes in PowerShell 5 (part 1)
PowerShell 5 comes with built-in support for classes. You can use this new feature to enhance existing .NET classes. Here is an example: let’s...
Show or Hide Windows
PowerShell can call internal Windows API functions, and in this example, we’d like to show how you can change the show state of an application...
Using Pester Tests to Test Anything
Pester is an open source module shipping with Windows 10 and Windows Server 2016, and can be downloaded from the PowerShell Gallery...
Reading Environment Variables Freshly
When you read environment variables in PowerShell, you probably make use of the “env:” drive. This line retrieves the environment...
Setting Environment Variables
When setting environment variables through the PowerShell “env:” drive, you are always just manipulating the process set. It applies to...
Checking Host
In the past, Microsoft shipped two PowerShell hosts: the basic PowerShell console, and the more sophisticated PowerShell ISE. Some users used code...
Playing with PowerShell 6.0
PowerShell is open source now, and the next big release of PowerShell is being developed in the open. If you’d like to take a peek preview,...
Caching Credentials Using JSON
When you need to cache logon credentials to a file, this is typically done by piping the credential to Export-Clixml which produces a rather lengthy...
Free Guides to Start With PowerShell
If you have colleagues that don’t know PowerShell, and you would like them to get started, here are three free learning resources:...