database-tools

Retrieve Yesterday’s Error Events

To retrieve all error events from a system log that occurred yesterday, here is how to calculate the start and stop times: PS> $end = Get-Date...

Creating Intelligent Variables

To create variables that calculate their content each time they are accessed, use access-triggered variable breakpoints. This line, for example,...

PowerShell Script Security Auditing

When you digitally sign scripts, you can easily tell whether a script was manipulated or comes from an untrusted source. Here is a function that can...

Re-Encoding ISE-Scripts

When you save scripts with the PowerShell ISE script editor, they are saved with the rather unusual "Big Endian Unicode" encoding....

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...

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

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:...

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...

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...

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...