Featured Blog
Empowering Law Firms: How SQL Server and Idera Tools Safeguard Legal Data
Using Script Validators with Variables
As pointed out in a previous tip, PowerShell 3.0 now supports the use of validators for variable assignments. This is a great way of ensuring that a...
Waiting for Service State
Most high-level cmdlets dealing with services have built-in code to wait for state changes. So when you run Restart-Service to restart a service,...
Controlling Numeric Range for Variables
In a previous tip we illustrated how in PowerShell 3.0, you can now use validators to restrict the data that can be assigned to a variable. Here is...
Mobile Dashboard Plugin Linux
Hi  I’ve recently tried to install the mobile dashboard plugin 1.2 on my rhel 6.3 monitor station running uptime 7.1, and noticed its only...
Killing All Remote PowerShell Sessions
In a previous tip we explained how you can enumerate who is connected to your machine via PowerShell Remoting, and how you can terminate individual...
Killing Remote PowerShell Sessions
To kill a remote PowerShell session that runs on your machine, you could kill the wsmprovhost.exe task associated with it, but identifying the...
Finding Remote Sessions Connected to Your Machine
Ever wanted to find out who is running a (hidden) remote PowerShell on your machine? Here's a simple one-liner: Get-WSManInstance -ConnectionURI...
Define Variable Checkers
When you assign a mandatory data type to a variable, then this will improve script robustness: whenever a value is (accidentally) assigned to that...
Make Parameters Mandatory and Optional at the Same Time
An often overlooked feature in PowerShell is the ability to make a function parameter both optional and mandatory - at the same time. Let's for...
Enabling Visual Styles
When you use Windows Forms dialogs and windows, you may have noticed that they show differently, depending on whether you launched your script from...
Finding PowerShell Module Requirements
PowerShell modules extend functionality by adding more cmdlets and/or providers. Modules support copy-and-paste deployment...
Using ValidatePattern attribute
PowerShell can validate parameters using regular expressions. This example accepts only computer names that start with "PC" followed by...
Creating Script Blocks from Strings
Sometimes you may want to create a script block dynamically from a string. This could be necessary to include local variable content, for example....
Analyzing Script Blocks
Script blocks are simply pieces of PowerShell code. You probably use them all the time in scripts and functions. A script block is defined by braces...
Creating Simple Custom Dialog
PowerShell can display custom dialogs easily. So if you're not satisfied with the dialog buttons available in a standard MsgBox dialog, simply...
Getting Screen Information
Ever needed to know the current screen resolution or related screen information? Here's an easy way of getting that information: Add-Type...
Disassembling C# Code
Adam Driscoll, another PowerShell MVP, has published a function called Get-MemberBody to PoshCode: http://poshcode.org/4127. In conjunction with the...
Understanding Profile Scripts
Whenever you want PowerShell to configure or execute code automatically on launch, the code needs to go into one of four profile scripts. They...
Opening a file with the default program on Windows and Mac
I've been using the windows API call ShellExec for years to pass in the file name of a file I want to launch programatically with the default...
Test Local User Account Credentials
Here is a snippet that verifies a local user account. Simply submit a username and a password. You get back either $true or $false: $username =...
Enabling High Performance Power Plan via Command Line
Hopefully, everyone knows by now that the default power plan in Windows 2008+ is “balanced” which can result in your CPUs being throttled down to...
Using "Using:" On Remote PowerShell Sessions (Part 2)
In a previous tip we talked about using PowerShell Remoting to execute code on a remote machine, and how to use "using:" to carry over...
Using RegEx to Filter Files
Get-ChildItem supports basic wildcards, but it does not support the rich feature set of regular expressions. If you combine Get-ChildItem with...
Enable PowerShell Remoting in Two Lines of Code
One common problem with enabling PowerShell Remoting on your box is public networks. As long as there are active network connection labeled as...
Using "Using:" On Remote PowerShell Sessions
When you use PowerShell Remoting to execute scripts and commands on another machine, you may have run into an issue like this: $class =...
Replacing Variable Names in ISE 3.0 Editor
If you want to replace variables in a PowerShell script, in PowerShell ISE 3.0 you can use the following function: function Replace-Variable {...
Working with Sensors, Devices and Platform Services in your C++ applications
All of our modern PCs, Smartphones, Tablets and other devices include more than just a screen, keyboard, mouse, memory, and storage. The devices We...
Quick Reference Sheets for PowerShell
PowershellMagazine.com has prepared a set of very useful quick reference sheets for PowerShell 3.0, the ISE editor and more. Microsoft now offers...
Controlling Admin PowerShell from Non-Elevated PowerShell
In a previous tip we illustrated how you can use Start-Process to launch an elevated PowerShell from within your script to do elevated tasks. The...
Reversing GUIDs
Active Directory and other services sometimes use a custom GUID format. To convert a GUID to that format, all blocks of the GUID need to be...