Beginning in PowerShell 5, you can assign a validator to a variable. The validator can take a regular expression, and once you assign new values to...
powertips
Using Profile Scripts
PowerShell by default “forgets” most settings on restart. If you’d like to “keep” settings, you use a profile script....
Optimizing Command Completion
The PowerShell console (powershell.exe, pwsh.exe) offers extensive completion support. When you enter a command and then add a space and a hyphen,...
Reading Registry Remotely (Part 2)
In the previous example we showed the code required to read registry values remotely from another machine using the old-fashioned DCOM protocol. If...
Reading Registry Remotely (Part 1)
If you cannot use PowerShell remoting, and you need to read registry values from another system via DCOM, here is some example code you might want...
Hardening PowerShell Script Block Logging Log
When you enable ScriptBlockLogging, PowerShell logs all PowerShell code that is executed on your machine. Even if it is disabled, any...
Manipulating Registry User Hive
Reading and writing values to the HKEY_LOCAL_USER hive in the registry is easy, because this hive is the same for all users. How would you read or...
Managing Windows Features (Part 2)
In Windows 10, unlike in Windows Server, you cannot use the Get-WindowsFeature and Add-WindowsFeature cmdlets to manage Windows features. However,...
Managing Windows Features (Part 1)
Windows 10 comes with a vast number of features, and only a subset is installed. Manually, you would open Control Panel and look at the Windows...
Running CMD commands in PowerShell
PowerShell by default does not support the native cmd.exe command such as „dir“. Instead, it uses historic aliases called...
Getting Excuses Automatically
Invoke-WebRequest can retrieve HTML info from web pages, and regular expressions can then scrape information from these pages. Here is some code...
Separating Variables in Expandable Strings
When you use double-quoted strings, you can expand variables inside of them like this: PS C:\> "Windir: $env:windir" Windir: C:\Windows...
Finding Windows Build Numbers
When you run winver.exe, you can easily retrieve the full Windows build number. Reading the build number from PowerShell is not as obvious. There is...
Checking for USB Devices
If you’d like to know whether a specific device is attached to your computer, you can use WMI to dump the names of all plug&play devices:...
Using PSGraph
PSGraph is an awesome free PowerShell library that you can use to visualize relationships. Before you can use PSGraph, you need to install its...
Using AD Filters with Cmdlets (Part 4)
In the previous tip we started to look at how cmdlets from the ActiveDirectory module (part of the free RSAT tools) can filter results, and looked...
Using AD Filters with Cmdlets (Part 3)
In the previous tip we started to look at how cmdlets from the ActiveDirectory module (part of the free RSAT tools) can filter results, and started...
Using AD Filters with Cmdlets (Part 2)
In the previous tip we started to look at how cmdlets from the ActiveDirectory module (part of the free RSAT tools) can filter results. You learned...
Using AD Filters with Cmdlets (Part 1)
The free RSAT tools come with the ActiveDirectory PowerShell module. You can use the cmdlets from this module to retrieve AD information such as...
Creating Temp File Names
Whenever you write information to disk, it makes sense to use unique temporary file names. If you use static file names and run your code more than...
File System Stress Test
If you’d like to generate super large files for stress test purposes, you don’t have to waste time pumping data into a file to make it...
Passing Commands via Parameter
Here is a rather unusual use case for function parameters: a user can pass an output command: function Get-ProcessList { param ( [string]...
Dealing with File Encoding and BOM
When you write text content to a file, PowerShell cmdlets let you specify the encoding. Encoding determines how characters are stored, and when...
Finding Nested Active Directory Memberships (Part 3)
In the previous tip we illustrated how you can find out the direct and indirect group memberships for a user. If you’d like to know the...