Powershell

Escaping Text Strings

HTML on web pages uses tags and other special characters to define the page. To make sure text is not misinterpreted as HTML tags, you may want to...

read more

Checking Host Name Type

To check whether a string contains a valid host name, you can use the CheckHostName() method provided by the System.URI type. It will return...

read more

Validating a URL

To make sure user input is a valid URL, you can use the System.URI type. Try to convert the raw string into this type. If it works, the string is a...

read more

Reversing Array Order

To reverse the order of elements in an array, the most efficient way is to use the [Array] type and its static method Reverse(): # Create an array...

read more

Validating IP-Addresses

To check for a valid IP-address, use the .NET Framework type System.Net.IPAddress and test whether the data can be converted into this format:...

read more

Validating Email-Addresses

To check for valid email addresses, you can use the .NET Framework type System.Net.Mail.MailAddress and test whether the data can be converted into...

read more

Exiting a Function

To exit a function immediately, use the return statement. The next function expects a name (including wildcards) and lists all matching processes....

read more

Quick Drive Info

Want to quickly get a number of interesting details for any drive? Use the .NET System.IO.DriveInfo class like this: New-Object System.io.DriveInfo...

read more

Ping and Range Ping

In PowerShell, you can access .NET methods directly so it is easy to add a ping functionality: $object = New-Object...

read more

Validating User Input

When writing a function that accepts parameters, you can strongly-type parameters so that an exception occurs when the user submits the wrong...

read more

Generate a New GUID

GUIDs are "Globally Unique Identifiers," which are so random that you can safely assume they are unique worldwide. GUIDs are used whenever...

read more

Discover about-Topics

PowerShell comes with a lot of documentation. It is just sometimes hard to find. For example, to get a list of all available operators, do this:...

read more

Automatic Aliases

All Get-Cmdlets (cmdlets that start with "Get") have an automatic type accelerator. You can use those cmdlets without the verb. So...

read more

Exploring Privileges

On Vista with UAC enabled, you are not Admin by default. It might be interesting to find out if PowerShell currently has Admin privileges enabled....

read more

Enumerating Drive Letters

Sometimes, you may want to find the next available drive letter for a network drive or enumerate drive letters for other purposes. An easy way to...

read more

Counting Items in a Folder

Get-Childitem returns all files in a folder. PowerShell returns an array if there are at least two items in a folder. To force PowerShell to always...

read more

Converting Numbers

The .NET convert class is a great help when you need to convert numbers between different systems. Here's how you can convert a decimal into a...

read more

Outputting HTML Reports

PowerShell can export results as HTML. Simply pipe the results to ConvertTo-HTML and save the result in a file. When you do that, it is wise to use...

read more