May 2010 - Power Tips

Share |

Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Powershell Plus

13 Free SQL Tools from Idera

Free Ebook: Mastering Powershell


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
  • Built-in Methods

    Strings contain all the methods you may need to access its content or manipulate it otherwise. Here is how you can list those methods: "Hello" | Get-Member -memberType * method For example, to trim all leading and trailing white space from a...
  • Stopping Programs Gracefully

    While Stop-Process will stop a process immediately in PowerShell, it will also destroy all data that hasn't yet been saved. You can try a more graceful approach that would give the user a warning and allow them to save data: $proc = Get-Process notepad...
  • Create HTML System Reports

    ConvertTo-HTML is a great way of creating system reports because you can combine information gathered from different sources into one report. The following code will create a report with service information that is gathered from Get-Service, operating...
  • Create HTML reports

    ConvertTo-HTML will convert text information into simple HTML, which can then be saved to disk. These reports will work fine, even though they are pretty ugly. Using just a simple HTML style sheet, your HTML reports will look a lot better: $style = @...
  • Printing Results

    You will discover that Out-Printer can print results to your default printer. You can also print to any other printer when you specify its name: Get-Process | Out-Printer -name 'Microsoft XPS Document Writer' You should ask WIMI if you need to...
  • Outputting Text Data to File

    When you output results to text files, you will find that the same width restrictions apply that are active when you output into the console. You should use a combination of Format-Table and Out-File with -Width to allow more width. Get-Process | Format...
  • Examining Object Data

    If you need to see all properties a result object provides, you should probably add Select-Object * to it like this: Get-Process -Id $pid | Select-Object * You will find that a much more thorough way uses Format-Custom. With this approach, you can specify...
  • Multi-Column Lists

    If you need to display a lot of information in as little room as possible, you should use Format-List with -Column: Get-Service | Format-Wide -Column 5 This will work well whenever you want to display only one property per result. ReTweet this Tip!
  • Create Groups (and Examine Alias groups)

    Format-Table has a parameter called -GroupBy which creates groups based on the property you supply. For example, you can use this to examine aliases and build groups with aliases that all point to the same command: Get-Alias | Format-Table -GroupBy Definition...
  • Getting IPv4 Addresses

    You should use WMI to list all IPv4 addresses assigned to a computer: Get-WMIObject win32_NetworkAdapterConfiguration | Where-Object { $_ . IPEnabled -eq $true } | Foreach-Object { $_ . IPAddress } | Foreach-Object { [ IPAddress ] $_ } | Where-Object...
  • Automating Native Commands

    You'll discover that some native commands require interactive keystrokes before they work. For example, to format a drive, for security reasons you need to enter the current volume name and then hit "Y." To automate these commands, you should...
  • Finding Update History

    Whenever Windows installs an update via Windows Update, it will log this in its windowsupdate.log file. PowerShell can then parse this file. You should use this to find out how many updates you received on which dates: Get-Content $env:windir \ windowsupdate...
  • Get Assigned IP Addresses

    If you've ever wanted to know all IP addresses assigned to a machine, you should use WMI: Get-WMIObject win32_NetworkAdapterConfiguration | Where-Object { $_ . IPEnabled -eq $true } | Select-Object IPAddress You can also connect to remote systems...
  • ExpandProperty rocks - sometimes

    Select-Object will select the object properties that you want to see. So it removes all properties you did not specify, but it always returns an object: Get-Process | Select-Object Name Often, you are not interested in an object but prefer the content...
  • Creating Range of Letters

    PowerShell can easily provide a range of numbers, but creating them is not that easy - unless you convert ascii codes into characters: 65..90 | Foreach-Object { "$([char]$_):" } ReTweet this Tip!
1 2 Next >
Copyright 2012 All rights reserved.