When you save scripts with the PowerShell ISE script editor, they are saved with the rather unusual "Big Endian Unicode" encoding....
Powershell
Digitally Signing PowerShell Scripts
In a previous tip, we illustrated how you access a code signing certificate that was installed on your computer. With such a certificate, you can...
Finding Code Signing Certificates
To digitally sign PowerShell scripts, you need a certificate with the purpose "CodeSigning". Here is how you find out which code signing...
How Large Are My Folders?
To find out the total size of all subfolders in a directory, try this function: function Get-FolderSize($Path=$home) { $code = { ('{0:0.0}...
HTML-Scraping with RegEx
To scrape valuable information from websites with PowerShell you can download the HTML code and then use regular expressions to extract what you are...
Finding Multiple RegEx Patterns
PowerShell comes with great support for regular expressions but the -match operator can only find the first occurrence of a pattern. To find all...
Creating Pipeline Filters
In a previous tip, we illustrated how a function can run inside a PowerShell pipeline. That's an excellent way to create filters. Here is a...
Using Functions inside the Pipeline
Code inside PowerShell functions always is placed in the begin, process, or end block. You may not have noticed this because when you don't do...
Forget the "Finally"-Block
When you handle errors using try/catch/finally, you may wonder what the finally block is for. Here is a demo: try { dir nonexisting:\ -ErrorAction...
Understanding and Handling Terminating Errors
To suppress errors in a cmdlet, you can use the common parameter -ErrorAction SilentlyContinue. Here is a sample: Get-WmiObject Win32_BIOS...
Use "E" in Numbers
To quickly define large integers, use the keyword "E" inside your number: PS> 64E6 64000000 ReTweet this Tip! http://bit.ly/pGRrMP
Executing PowerShell Commands with Full Privileges
If a script needs to run only particular commands with full Administrator privileges, you can run those in a separate elevated shell. $code =...
Running Script with Full Privileges
On UAC-enabled systems, to make sure a script is running with full admin privileges, add this code at the beginning of your script:...
Getting Information about Speed Traps and Traffic Jams
PowerShell can read RSS feeds in just a couple of lines of code. Many radio broadcasters maintain RSS feeds with information about speed traps and...
Text-to-Speech
Here is a fun function that converts text to speech. It even has a switch parameter called -Drunk to change the voice accordingly: function Out-Text...
Latest Process Activity
To find out whether a computer is idling for a long time or actually doing something, here is a function that returns the last process that was...
Getting NIC IP addresses and MAC addresses
WMI can return network information such as your current IP address and MAC address. Here is a sample how PowerShell can utilize and beautify the...
Checking Windows Updates Remotely
In a previous tip you learned how to list installed Windows Updates. Unfortunately, this only works for local machines. Provided you have enabled...
Controlling PSComputerName in Remoting Data
Whenever you use Invoke-Command to remotely execute code, you will notice that PowerShell automatically adds the column PSComputerName to your...
Listing Windows Updates
There is a not widely known COM object that you can use to list all the installed Windows Updates on a machine. Here is the code: $Session =...
Determine Functions Pipeline Position
Assume your function wanted to know whether it is the last element in a pipeline or operating in the middle of it. Here is a way for a function to...
Displaying Balloon Tip
Let's assume your script wants to share status information via a balloon message in the system tray area. Here is a sample:...
Saving History to Script
PowerShell is all about trial and error, and when you want to save your interactive input to a script file, this is how it could be done:...
Forwarding Selected Parameters
In a previous tip you learned how you can forward function parameters to cmdlets. But what if you just want to forward some of the parameters? Here...