database-tools

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

Outputting Calculated Properties

Format-Table is a very convenient cmdlet to output data as table. You can pick the object properties you want to output like this: Dir |...

Finding Old Files

Occasionally, you might want to find files that are older than a give number of days to delete or backup those. A simple filter can provide that...

Working with Arrays

Creating arrays in PowerShell is easy using the comma delimiter. The next line creates an array with five elements: $myArray = 'Hello', 12,...

Converting Results into Arrays

Whenever you call a function or cmdlet, PowerShell uses a built-in mechanism to handle results: If no results are returned, PowerShell returns...

Finding Duplicate Files

Hash Tables are a great way to find duplicates. Simply use the Hash Table as lookup to see if the file (or element) was already added to the Hash...

Converting Hash Tables to Objects

Hash Tables are convenient but are not true objects. This is bad because you are unable to output the hash content to formatting cmdlets or export...

Sorting Hash Tables

Hash Tables store key-value pairs, and you normally cannot sort its content. Let's define a Hash Table first to examine this: $hash =...

Using Hash Tables

Hash Tables are a great way to organize data. A hash table stores key-value-pairs. To create a new hash table variable, try this: $person = @{} You...

Strongly Typed Variables

Unless you override how PowerShell stores variable content, you may find that PowerShell does not automatically pick the best type. For example,...

Making Variables Constant

If you need to write more robust scripts, it makes sense to write-protect certain variables. Whenever you want a variable to set its content as...

Add Descriptions to Variables

Keeping track of a variable’s purpose can be accomplished by assigning a clear text description: $ip = '10.10.10.10' Set-Variable ip...

Assigning Variables

With PowerShell, you can assign values to multiple variables. For example, to initialize three variables to the same default value, use this: $a =...