July 2012 - Power Tips

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

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
  • Identifying PowerShell Host

    If your script requires a real console, or if your script requires PowerShell ISE features, it may be a wise thing to check which host is actually running your script. Here's a one-liner that tells you the name of the current host application: PS...
  • Find WMI Classes

    Get-WmiObject is a great cmdlet that returns all instances of a WMI class: PS > Get-WmiObject -Class Win32_LogicalDisk All you need to know is the name of the appropriate WMI class that represents what you are looking for. Fortunately, Get-WmiObject...
  • Adding Type Accelerators

    Type accelerators are shortcut names that represent .NET types. For example, you can use [XML] instead of [System.Xml.XmlDocument]. By default, PowerShell only contains type accelerators for the most common .NET types but you can easily add more. The...
  • Rename PowerShell Scripts

    Rename-Item can easily batch-rename large numbers of files, simply by piping file objects into it. Here is a sample that finds all PowerShell script files in your home folder and checks whether they contain the phrase "Untitled" followed by...
  • Verifying Restore Points

    When you create a new restore point with Checkpoint-Computer, you do not get back any feedback telling you whether the operation succeeded. Fortunately, you can easily lookup the corresponding event log entry: PS > Get-EventLog -LogName application...
  • Enabling and Disabling Computer Restore

    In a previous tip we shared how you can use PowerShell to create restore points and restore your system state in case something went bad. There are two more cmdlets that control which drives are monitored by system restore points: Enable-ComputerRestore...
  • Backing Up System State

    Let's assume your script needs to change a bunch of system settings. The worst thing that could happen is if your script breaks in the middle of changing things, leaving you with only parts of changes. Provided system restore points are enabled on...
  • Discarding Unwanted Information

    If you want to dump results from a command, there are a number of ways. While they all do the same, they have tremendous performance differences: PS > ( Measure-Command { 1 . .100000 | Out-Null }) . TotalMilliseconds 1114 , 3006 #!!!!!!!!!!! PS >...
  • Investigating USB Drive Usage

    With two lines of PowerShell code, you can dump the USB storage history from your registry and check which devices were used in the past: PS > $key = ' Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR\*\* ' PS > Get-ItemProperty...
  • Installing MUI-Packs

    The current PowerShell V3 Beta requires an English Windows operating system. That's bad news for anyone running Windows 7 Professional or Home since you cannot install language packs (MUIs) on those. There is a free tool though that allows you to...
  • Finding All Object Properties

    By default, PowerShell only displays a limited set of object properties. To view all available properties, add the following pipeline element: PS > Get-WmiObject Win32_BIOS PS > Get-WmiObject Win32_BIOS | Select-Object * -First 1 The Select-Object...
  • Finding True WMI Properties

    When you use Get-WmiObject to retrieve WMI objects, PowerShell adds a number of supporting properties. If you want to display only the native WMI properties, you first need to sort out the additional property names and then exclude them. This would get...
  • Finding Current Script Paths

    Here's a useful function that you can paste into your scripts. It will tell you the current location the script is executed from. function Get - ScriptDirectory { $Invocation = ( Get-Variable MyInvocation -Scope 1 ) . Value try { Split-Path $Invocation...
  • Creating New Scripts in ISE

    Often, you first play around with PowerShell commands interactively, and then once those commands do what you want, you can copy them to your script editor and turn them into scripts and functions. Here is a little helper function that takes all your...
  • Copying Command History to Clipboard

    Here's a one-liner that copies all commands from your command history to the clipboard. From there, you could paste them into your favorite PowerShell editor and make your interactive code a script: PS > Get-History | Select-Object -ExpandProperty...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.