Ever wanted to display a dialog box from PowerShell rather than spitting out console text? Then try this function: function Show-MsgBox { param (...
powertips
ASCII Table
Here’s a simple way of creating an ASCII table through type casting: 32..255 | ForEach-Object { 'Code {0} equals character {1}' -f $_, [Char]$_ }...
Pipeline Used Or Not?
Sometimes you may want to know if your function received parameters over the pipeline or direct. Here is a way to find out: function test {...
Using Background Jobs to Speed Up Things
PowerShell is single-threaded and can only do one thing at a time, but by using background jobs, you can spawn multiple PowerShell instances and...
Validate IP Addresses
You can use regular expressions and the –match operator to validate user input. Here’s a loop that keeps asking until the user enters a...
Converting UNIX Time
Surprisingly, when you read some values from the Windows Registry, they do not seem to be in a readable format: $key =...
Adding Support For –WhatIf and -Confirm
Ever wanted to support the risk mitigation parameters –WhatIf and –Confirm in your functions, too? Here’s a code template that you...
Finding Disk Controller Errors
This line will analyze your system event log for disk controller errors: PS> Get-EventLog -LogName System -InstanceId 3221487627 -ea 0 |...
Adding More Fonts to PowerShell Console
Tired of using the boring default fonts in PowerShell? There are more monospaced fonts on your system. You just need to allow the console to use...
Reading Registry Values with Powershell
In a previous tip we presented the functions New-RegKey and Set-RegistryValue to you which made creating registry keys and values very easy. Here is...
Creating Registry Values
In a previous tip we introduced the new function New-RegKey that could create one or more registry keys. Here is a function that creates registry...
Creating Registry Keys
With this new function, it is simple to create new registry keys (including missing parent keys) in all registry hives. All you need are proper...
Listing Domains in Forest
Here is a function that lists all the domains in your forest: function Get-Domain{ $Root = [ADSI]"LDAP://RootDSE" try { $oForestConfig =...
Turning On Standby-Mode
To programmatically enter standby mode, you can use native .NET code like this: function Invoke-Standby { Add-Type -AssemblyName...
Correctly Returning Exit Codes
When you launch a PowerShell script from outside PowerShell, you may want to return an exit code to the caller so that the caller knows if your...
Safely Running PowerShell Scripts
If you want to run a PowerShell script from outside PowerShell, for example from within a batch file, you probably know that you need to prepend...
Adding PowerShell Goodies to Server 2008 R2
Windows Server 2008 R2 comes with a PowerShell module called ServerManager which in turn allows you to add additional features to the server....
Recording Audio Text Files
Did you know that PowerShell can record audio messages? All you need is some text. You can then turn the text into spoken language, convert it to a...
Enter Hibernation Mode
Maybe you are running lengthy tasks at night. Sometimes you may want to place the machine into hibernation once your script is done. Here’s a...
Make PowerShell Speak!
By adding a new system type called System.Speech, you can make PowerShell speak out loudly: Add-Type -AssemblyName System.Speech $synthesizer =...
Create Group Policy Reports
Windows Server 2008 R2 comes with the GroupPolicy PowerShell module. You might have to install that feature first before you can use it – run...
Admin Privileges Enabled?
If you want to know whether your script has currently full Administrator privileges, here is an (admittedly long) one-liner that tells you:...
Locking Workstation
If you ever feel the need to lock your interactive session via PowerShell, here’s a function that can do this (and also illustrates how to use...
Logging Off
Stop-Computer and Restart-Computer can shutdown and restart a machine, but there are things they cannot do, for example logging off the current...