database-tools

Getting Image Details

PowerShell can access COM-Objects as there are many useful objects present on a system. For example, WIA.Image can return all kinds of useful...

Picking Random Items

In PowerShell V2, Get-Random retrieves as many random numbers as you like, allowing you to use this random number generator in many scenarios. A...

Restarting Processes

You may want to occasionally restart a single-instance process. However, shutting down a process does not necessarily mean it is killed in that...

Finding Unwanted Output

PowerShell has an extremely flexible way of submitting return values. Instead of explicitly setting the return value of a function, PowerShell...

Deleting Event Logs

Working with event logs has become a lot easier in PowerShell v.2, and you have seen how you create and maintain your own logs. So, if you'd...

Creating Your Own Eventlog

In PowerShell v.2, it is very easy to create and maintain your very own event logs to track errors in your scripts or other automation solutions....

Organizing Windows Event Logs By Source

There are numerous Windows event logs and you now have full control using Get-WinEvent in PowerShell v.2. Instead of searching for specific event...

Getting Process Based On Window Title

It isn't always easy to pick the right process because the process ID or process name may not be known or ambiguous. If the process has a window...

Getting Process Windows Titles

Get-Process retrieves all running processes and a wealth of information attached to them. One especially useful property is mainWindowTitle which...

Loading New Windows 7 Modules

Windows 7 comes with a bunch of modules that are not loaded by default. Use this to see which modules are available: Get-Module -listAvailable For...

Accessing Hidden Module Members

Modules in PowerShell v.2 can declare which functions, variables, aliases etc. are public and visible to the caller and which ones are hidden. With...

Managing PowerShell Modules

In PowerShell v.2, all new modules work like libraries and can be loaded using Import-Module to gain access to all public functions, variables,...

Updating PowerShell Modules

In a previous tip, you learned about the new modules in PowerShell v.2, which can be loaded using Import-Module. Once you have loaded a module, it...

Creating Script Modules

In PowerShell v.2, there is a new feature called "module," which is a file with the extension .psm1 and behaves almost exactly like a...

Trap and Try/Catch

Trap, which has been around since PowerShell v.1, is designed to catch errors and works like this: trap { Write-Host -foregroundcolor Yellow `...

Which PowerShell Version Am I Running

As PowerShell v.2 becomes more common , you may want to check which PowerShell version a machine is running. Use this to differentiate between v.1...

Is PowerShell Available?

As PowerShell becomes more important, you may want to automatically check whether it is available on a machine. To determine whether any PowerShell...

Using Hash Tables Instead of Switch

You may have already used Switch to translate input and output values like this: function Get-Name($number) { switch ($number) { 1 { "One"...

Processing Switch Return Value

You probably know that the Switch statement checks against a value and returns whatever you have defined for this condition like so: function...

Finding Script Errors

There is scripting expertise built-in to PowerShell v.2 that can be activated like this: set-strictmode -version 1set-strictmode -version 2 Use the...

Getting System Uptime

If you'd like to determine a system's uptime, you should use WMI and convert the WMI date into a more readable format: function...

Display Work Hours in Prompt

Up for some fun with your prompt? Make it a bit shorter, display the minutes (or hours) you have been working so far, and show the current path in...

Accessing Current PowerShell Process

If you ever want to access the process that is executing your current PowerShell session, use the $pid automatic variable which tells you the...

Adding Custom Methods to Types

In a previous tip, we have added a new script method to a string called Words() which would split the string into words. But is it worth the effort?...