PowerShell uses the US/English date format when converting user input to DateTime, which can cause unexpected results if using a different culture....
ps1
Casting a Type Without Exception
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...
Order Matters
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...
Filtering Based On File Age
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...
Accessing Date Methods
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...
Using Cultures
Since PowerShell is culture-independent, you can pick any culture you want and use the culture-specific formats. The following script instantiates...
Outputting Nicely Formatted Dates
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...
Stopping and Disabling Services
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...
Accessing Static .NET
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...
Arrays of Strings
In PowerShell, you can multiply strings: the string is repeated which can be useful for creating separators: '-' * 50 This works for words,...
Quick Loops
Normally, creating a simple loop in PowerShell can be a bit awkward: for ($x=
Understanding Exceptions (and why you can’t catch some errors)
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...
Understanding Trap Scope
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...
Using Traps and Error Handling
Traps are exception handlers that help you catch errors and handle them according to your needs. A Trap statement anywhere in your script: Trap {...
Show Battery Status as Prompt
The PowerShell console prompt can be easily changed by simply changing the prompt function to change the prompt text. If you are working with a...
Validate User Input
When you ask users for input you never know what they enter so it is a good idea to validate user input before using it. A great and easy way to do...
Multidimensional Arrays
PowerShell supports two types of multi-dimensional arrays: jagged arrays and true multidimensional arrays. Jagged arrays are normal PowerShell...
Manipulating Arrays Effectively
While you can add and remove array elements with PowerShell arrays, this is an expensive operation and not recommended with large numbers of...
Using COM Objects to Say "Hi!"
If you have ever written scripts using VBScript, you probably know COM objects which are DLLs and work like command libraries. You can use COM...
Downloads with Progress Bar
If you'd like to download larger files from the Internet and get a progress indicator, you can load the .NET Visual Basic assemblies, which...
Downloading Files from the Internet
You can tap into the wealth of .NET methods easily. Use New-Object to instantiate a new .NET class, and off you go. For example, instantiate an...
Finding System Folders
When you automate file system tasks, you may want to know where special folders such as MyPictures or Documents are located. The .NET class...
Finding Out a Scripts Parent Folder
If you need to find helper files that are stored in the same folder, you may want to know where a given script is stored. The automatic variable...
Finding the Current User
Should you try and use PowerShell as a log-on script, you may want to know who is actually running the script to access user specific folders or...