PowerShell uses the US/English date format when converting user input to DateTime, which can cause unexpected results if using a different culture. For example, on German systems "1.3.2000" resolves to March 1, 2000. PowerShell can convert this...

Read-Host is a useful cmdlet to use to ask for user input. However, it returns user input always as generic string. Of course, you can always convert the user input to a more specialized type, like DateTime, to calculate time spans: $date = [ DateTime...

Here is a challenge for you. The following code is a simple currency converter. However, when you run it, you'll notice it doesn't convert correctly. Instead, you always get back the result you entered: $number = Read-Host 'Enter amount in...

Every so often, you'll need to filter files by age. Maybe you'll only want to see files that are older than 20 days old and delete them or back them up. So, you need a way to filter file age relative to the current date. Here is a custom filter...

While Get-Date returns the current date and time, it really returns a DateTime object. You can use this object to find out more about the date or to calculate date and time offsets as it has a number of very useful properties and methods. $date = Get...

Since PowerShell is culture-independent, you can pick any culture you want and use the culture-specific formats. The following script instantiates the Japanese culture, outputting a number as currency first in your current culture and then in the Japanese...

Get-Date provides you with the current date and time. With the -format parameter, you can add style to it. For example, use -format with a lowercase d to just output a short date: Get-Date -Format d You can get a list of format characters directly at...

You may find that Vista's new Instant Search can sometimes get out of hand and slow down your machine. Temporarily disabling and then stopping the search service is one way to deal with this issue: Set-Service wsearch -startupType Disabled Stop-Service...

Finding cmdlets by name is easy: Get-Command * service * -commandType Cmdlet But how can you list all cmdlets that support a given parameter? If you'd like to see all cmdlets with a -List parameter? The easiest way is to use Get-Help with the parameter...

You can start to explore the power of .NET with PowerShell's built-in .NET access.. All you will need are square brackets to access static classes. For example, here is a code snippet that resolves a host name: [ system.net.Dns ]:: GetHostByName ...

In PowerShell, you can multiply strings: the string is repeated which can be useful for creating separators: '-' * 50 This works for words, too: 'localhost' * 10 You can create a text array by converting the text to an array by first wrapping...

Normally, creating a simple loop in PowerShell can be a bit awkward: for ( $x = 1; $x -le 10; $x ++ ) { $x } A much more readable way works like this (and uses an array internally): foreach ( $x in 1..10) { $x } Loops are fun as you can easily create...

Traps are a great way of catching exceptions and handling errors manually but this does not seem to work all of the time. This example catches the error: Trap { 'Something terrible happened.' ; Continue } 1 / $null However, this example does not...

Traps are a great way of handling errors but you may want to control where PowerShell continues once an error occurs. There is a simple rule: a trap that uses the Continue keyword continues execution in the next line in the scope of the current trap....

Traps are exception handlers that help you catch errors and handle them according to your needs. A Trap statement anywhere in your script: Trap { 'Something awful happened' } 1 / $null Whenever an error occurs and an exception is raised, PowerShell...