PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Forum experts available to answer your PowerShell questions

Power Tips

Power Tips

Syndication

  • Using -f Operator to Combine String and Data

    All PowerShell Versions Strings enclosed by double-quotes will resolve variables so it is common practice to use code like this: $name = $host . Name "Your host is called $name." However, this technique has limitations. If you wanted to display...
  • Playing WAV Sounds

    PowerShell 3.0 or later To play a WAV sound file in a background process, PowerShell can use the built-in SoundPlayer class. It accepts a path to a WAV file and lets you then decide whether you want to play the sound once or repeatedly. This would play...
  • System Uptime

    All PowerShell Versions Windows starts a high definition counter each time it boots, and this counter will return the milliseconds the system runs: $millisecondsUptime = [ Environment ] :: TickCount "I am up for $millisecondsUptime milliseconds!"...
  • Finding Attached USB Sticks

    All PowerShell Versions If you'd like to know whether there are currently USB storage devices attached to your computer, WMI can help: Get-WmiObject -Class Win32_PnPEntity | Where-Object { $_ . DeviceID -like ' USBSTOR* ' } This returns all...
  • Test Service Responsiveness

    All PowerShell Versions To test whether a particular service is still responding, use a clever trick. First, ask WMI for the service you want to check. WMI will happily return the process ID of the underlying process. Next, look up this process, and the...
  • WMI Device Inventory

    All PowerShell Versions The WMI service can report plenty of details about the computer hardware. Typically, each type of hardware is represented by its own WMI class. It's not easy to find out the names of such hardware classes, though. Since all...
  • Get Sleep and Hibernation Times

    All PowerShell Versions If you want to find out whether a computer is frequently put into sleep or hibernation mode, here is a function that reads the appropriate event log entries and returns a table with details, reporting when the computer was put...
  • Understanding Sequential Filtering

    All PowerShell Versions When you parse text-based log files, or need to filter other types of information, you typically use Where-Object. Here are the common scenarios that illustrate how to combine filters: # logical AND filter for ALL keywords Get...
  • Filtering Hotfix Information

    All PowerShell Versions Get-HotFix is a built-in cmdlet that returns the installed hotfixes. It has no parameter to filter on hotfix ID, though. With a cmdlet filter, you can easily focus on the hotfixes you are after. This example returns only hotfixes...
  • Getting Shutdown Information

    All PowerShell Versions Windows logs all shutdown events in its System event log. From there, you can extract and analyze the information. Here is a function that looks for the appropriate event log entries, reads the relevant information from the ReplacementStrings...
  • Copying Command History

    All PowerShell Versions If you played with PowerShell and suddenly realize that you would actually like to keep the commands you played with, try this simple one-liner: ( Get-History ) . CommandLine | clip It copies all commands from your command history...
  • Searching Files with Regular Expressions

    All PowerShell versions Get-ChildItem does not support advanced file filtering. While you can use simple wildcards, you cannot use regular expressions. To work around this, add a cmdlet filter and use the operator -match. This example will find all files...
  • Getting Files with Specific Extensions Only

    All PowerShell versions When you use Get-ChildItem to get a list of files, you may have noticed that the -Filter parameter occasionally returns more files than you’ve expected. Here is an example of this. This line does not just return files with...
  • Correcting ISE Encoding

    All PowerShell versions When you run a console application inside the ISE editor, non-standard characters such as “ä” or “ß” do not show correctly in results. To correct the encoding ISE uses to communicate with its...
  • Using the OpenFile Dialog

    PowerShell 3.0 and newer Here’s a quick function that works both in the ISE editor and the PowerShell console in PowerShell 3.0 and above): Show-OpenFileDialog. function Show-OpenFileDialog { param ( $StartFolder = [ Environment ] :: GetFolderPath...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.