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...
ps1
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:...
Identifying Problematic Execution Policy Settings
PowerShell uses execution policy to determine which scripts to run. There are in fact five scopes where execution policy can be defined, and to see...
Checking Execution Policy
Execution policy determines what kind of scripts PowerShell will execute. You need to set execution policy to something other than Undefined,...
Classes (Static Members – Part 6)
Classes can define so-called “static” members. Static members (properties and methods) can be invoked by the class itself and do not...
Using Classes (Constructors – Part 5)
Classes can have so-called constructors. Constructors are methods that initialize a new object. Constructors are simply methods that share the name...
Using Classes (Overloading – Part 4)
Methods in classes can be overloaded: you can define multiple methods with the same name but different parameters. This works similar to parameter...
Using Classes (Adding Methods – Part 3)
One of the great advantages of classes vs. [PSCustomObject] is their ability to also define methods (commands). Here is an example that implements a...
Using Classes (Initializing Properties – Part 2)
Class properties can be assigned a mandatory type and a default value. When you instantiate an object from a class, the properties are pre-populated...
Using Classes (Creating Objects – Part 1)
Beginning in PowerShell 5, there is a new keyword called “class”. It creates new classes for you. You can use classes as a blue print...