In PowerShell v.2, Get-WinEvent provides access to events written to the numerous Windows event logs. In addition, you can also examine event...
ps1
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...
Handling Event Logs with Get-WinEvent
In PowerShell v.1, Get-Eventlog would retrieve standard event log entries from event logs like "System" or "Application," but...
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...
Checking Whether Hash Table Contains Key
In the previous tip, you used a hash table to translate input values. However, unlike Switch-statements, Hash Tables have no "default" so...
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...
Count Your Work: Calculating Process Runtime
Each process stores its start time, so it is fairly easy to find out when the process was launched. If you'd like to know when you started your...
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...