PowerShell comes with great support for regular expressions but the -match operator can only find the first occurrence of a pattern. To find all...
database-tools
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...
Clean your TEMP folder!
When disk space gets low, you may want to clean up your temporary folder. The code deletes all files that are older than 30 days to make sure...
Filtering Files or Folders
To filter folder content by file or folder, check whether the Length property is present. It is present for files and missing in folders: Dir...
Office365 Cmdlets
Office365 comes with a complete set of PowerShell cmdlets. To review the cmdlets and what you can do with them, visit this URL:...
Forwarding Parameters
To forward function parameters to a cmdlet, use $psboundparameters automatic variable and splatting. Here is a sample: function...
How Long Has Shell Been Running?
To find out how long your PowerShell session has been running, try this code snippet: ((((Get-Date)-(Get-Process -id $pid).starttime) -as [string])...