database-tools

Executing with Timeout

Start-Process can start processes but does not support a timeout. If you wanted to kill a runaway process after a given timeout, you could use an...

read more

Finding Drive Letters

Here is a simple function to find out the reserved drive letters: #requires -Version 3 function Get-DriveLetter { (Get-WmiObject -Class...

read more

Quickly Finding Scripts

To quickly locate a PowerShell script anywhere in your MyDocuments folder, take a look at this Find-Script function: #requires -Version 3 function...

read more

Hiding Variable Content

When you override the ToString() method of an object you control how this object is displayed. The object content stays untouched, though: $a = 123...

read more

Remove Array Elements

Did you ever need to compare two arrays? Compare-Object might help. Check this out: $array1 = 1..100 $array2 = 2,4,80,98 Compare-Object...

read more

Shortening Text

Let's assume you want to chop off some text at the end of a string. This is the traditional approach using string operations: $text = "Some...

read more

Avoid Using Redirection

While you can still use the old redirection operator to write command output to a file, you should rather use PowerShell cmdlets instead. Here is...

read more

Encode PowerShell Commands

When you need to run code as a PowerShell command in a separate powershell.exe, it is not always safe to submit the code. Depending on from where...

read more

Define Multiline Text

When you need to define multiline text, in PowerShell you typically use here-strings like this: $text = @" I am safe here I can even use...

read more

Current Script Path

In PowerShell 1.0 and 2.0, you needed a lot of weird code to find out the current script location: # make sure the script is saved and NOT...

read more

Change ISE Zoom Level

The PowerShell ISE sports a zoom slider at its lower right edge, and you can control this slider with PowerShell code. So you could set defaults for...

read more