Powershell

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

Adding Custom Methods to Objects

In a previous tip, you learned how to add custom properties to objects. Today, we want to show you how to add custom methods and also give an...

Adding Custom Properties

You may have heard that PowerShell can add custom properties to objects. While we are not going into much detail about this here, we'd like to...

CSV-Files With Culture

In a previous tip, you learned that CSV files use different separators, depending on your culture. While you were unable to select a separator in...

CSVs with Alternative Delimiters

In PowerShell V1, creating CSVs wasn't very flexible because PowerShell was limited to the comma as separator. In many cultures, different...

Persisting Objects with XML

In the previous tip, you learned that Export/Import-CSV does not persist property types. Instead, all properties are converted to string. To...

1 95 96 97 98 99 104