Power Tips

Welcome to the archive of tips delivered through Tobias' Tip of the Day RSS Feed and Your Power Tip of the Day email. Subscribe in the sidebar to get the latest tips!

Sort by: Most Recent | Most Viewed | Most Commented
  • 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 Select-Object to first limit the object properties to only those you want to see in your report, otherwise...
  • Add Custom Properties

    While objects contain a wealth of information, this information sometimes isn't in the right format. Let's take WMI objects representing disk drives. All size properties return bytes so you may want to show megabytes or gigabytes: Get-WMIObject...
  • Accessing Individual WMI Instances

    You always get back all instances of a given WMI class when using Get-WMIObject. However, what if you just wanted to get a specific instance? Or you just wanted to find out how much space is left on drive C:? The next line gives you all drives: Get-WMIObject...
  • Free Space on Disks

    You can use WMI to determine how much free space is available on any given disk: Get-WMIObject Win32_LogicalDisk | Foreach-Object { 'Disk {0} has {1:0.0} MB space available' -f $_ . Caption , ( $_ . FreeSpace / 1MB) } Here is how it works: Get...
  • Converting User Input to Date

    PowerShell uses the US/English date format when converting user input to DateTime, which can cause unexpected results if using a different culture. For example, on German systems "1.3.2000" resolves to March 1, 2000. PowerShell can convert this...
  • Casting a Type Without Exception

    Read-Host is a useful cmdlet to use to ask for user input. However, it returns user input always as generic string. Of course, you can always convert the user input to a more specialized type, like DateTime, to calculate time spans: $date = [ DateTime...
  • Order Matters

    Here is a challenge for you. The following code is a simple currency converter. However, when you run it, you'll notice it doesn't convert correctly. Instead, you always get back the result you entered: $number = Read-Host 'Enter amount in...
  • Filtering Based On File Age

    Every so often, you'll need to filter files by age. Maybe you'll only want to see files that are older than 20 days old and delete them or back them up. So, you need a way to filter file age relative to the current date. Here is a custom filter...
  • Accessing Date Methods

    While Get-Date returns the current date and time, it really returns a DateTime object. You can use this object to find out more about the date or to calculate date and time offsets as it has a number of very useful properties and methods. $date = Get...
  • Using Cultures

    Since PowerShell is culture-independent, you can pick any culture you want and use the culture-specific formats. The following script instantiates the Japanese culture, outputting a number as currency first in your current culture and then in the Japanese...
  • Outputting Nicely Formatted Dates

    Get-Date provides you with the current date and time. With the -format parameter, you can add style to it. For example, use -format with a lowercase d to just output a short date: Get-Date -Format d You can get a list of format characters directly at...
  • Stopping and Disabling Services

    You may find that Vista's new Instant Search can sometimes get out of hand and slow down your machine. Temporarily disabling and then stopping the search service is one way to deal with this issue: Set-Service wsearch -startupType Disabled Stop-Service...
  • Finding Cmdlets With a Given Parameter

    Finding cmdlets by name is easy: Get-Command * service * -commandType Cmdlet But how can you list all cmdlets that support a given parameter? If you'd like to see all cmdlets with a -List parameter? The easiest way is to use Get-Help with the parameter...
  • 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 classes. For example, here is a code snippet that resolves a host name: [ system.net.Dns ]:: GetHostByName ...
  • 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, too: 'localhost' * 10 You can create a text array by converting the text to an array by first wrapping...
1 2 3 4 Next >
Copyright 2008 PowerShell.com. All rights reserved.