Ever wanted to support the risk mitigation parameters –WhatIf and –Confirm in your functions, too? Here’s a code template that you...
Powershell
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...
Check for 64-bit Environment
In PowerShell v3 (CTP2 publicly available) it is finally a snap to determine whether you are on a 64-bit machine and/or shell. PowerShell 3.0 is...
Stripping Decimals Without Rounding
When you divide numbers and just want the decimals before the decimal point, you could cast the result to integer. However, this would also round...
The Two Faces of -match
The -match operator can be extremely useful because it accepts regular expression patterns and extracts the information that matches the pattern:...
Finding Email of Logged On User
In an Active Directory environment, PowerShell can easily find the currently logged on user and retrieve AD information about that user, for...
Remotely Launching Processes
Unfortunately, the Start-Process cmdlet has no -ComputerName parameter so you cannot use it to launch processes on remote machines. Use WMI instead!...
Keeping Remote Programs Running
When you use PowerShell Remoting (like the Enter-PSSession cmdlet) to connect to another machine and then start a program using Start-Process, the...