Power Tips

Share |

Join PowerShell.com!
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
  • Read-Only and Strongly Typed Variables

    All PowerShell versions To make PowerShell scripts more robust, you can code a lot of requirements right into your script variables. When you do this, PowerShell monitors these requirements for you, and throws an error if someone breaks your rules. Requirement...
  • Using Constants

    All PowerShell versions Variables in PowerShell are volatile. You can overwrite and delete them – unless you create constants. Constants can only be created when there is no such variable yet. This line creates a constant named “cannotChange”...
  • Including Resources with Your Scripts

    PowerShell 3.0 and later If your script needs additional resources, like text lists of server names, or picture files, or anything else, then make sure your script stays portable. Never use absolute path names to refer to your resource files. Instead...
  • Using “more” in the PowerShell ISE

    PowerShell ISE In the PowerShell console, you can pipe commands to the old-fashioned “more.com”, or better yet, to Out-Host –Paging. This will display data page by page, asking for a key press to continue: PS> Get-Process | more PS>...
  • Read User Profiles from Registry

    All versions To find out which users have a (local) user profile on your machine, and where this profile is located, try this snippet: $path = ' Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\* ' Get-ItemProperty...
  • Reading Associated File Extensions from Registry (Part 2)

    All versions In a previous tip you learned how a one-liner can read multiple registry keys. In part 2, check out this one-liner: $lookup = Get-ItemProperty Registry :: HKCR \. [ a -f ] ?? | Select-Object -Property PSChildName , ' (default) ' ...
  • Reading Associated File Extensions from Registry

    All versions PowerShell code can be extremely dense. Here is a one-liner that reads all associated file extensions from the Windows Registry: Get-ItemProperty Registry :: HKCR \. * | Select-Object -Property PSChildName , ' (default) ' , ContentType...
  • Sort Things with Type

    All Versions Sort-Object is your one-stop solution for sorting. If it’s primitive data, simply pipe it to Sort-Object. If it is object data, specify the property you want to use for sorting: # sorting primitive data 1 , 5 , 2 , 1 , 6 , 3 , 12 ,...
  • Opening Webpages from PowerShell

    All versions Let’s assume you would like to open your favorite websites in a browser when you start your day. PowerShell can do this for you easily. It depends a bit how you would like the pages to open, though. When you use Start-Process, you can...
  • Measuring Website Response (and Execution Times)

    PowerShell 3.0 and later Sometimes it is important to know just how long a command takes. For example, to monitor web site response times, you could use Invoke-WebRequest. Measure-Command measures execution time. $url = ' http://www.powershell.com...
  • Unfolding Object Data Structure

    PowerShell 3.0 and later Objects can contain nested properties, and the data you are after may be “somewhere” inside an object. To display an object with all of its properties and subproperties expanded, convert it to JSON. This gives you...
  • Suppress Confirmation

    All PowerShell Versions Some cmdlets (like Remove-ADGroupMember) automatically ask for confirmation. This can be a problem in scripts running unattended. To suppress unwanted confirmation dialogs, explicitly set the -Confirm switch parameter to false...
  • Getting Cmdlet Help No Matter What

    PowerShell 3.0 and later Beginning in PowerShell 3.0 PowerShell no longer ships its help files. Instead, you need to download them via Update-Help, and since help files are stored inside the (protected) PowerShell folder, a normal user cannot do this...
  • Examining Wi-Fi Adapters and Power Management

    Windows 8.1/Server 2012 R2 Windows 8.1 and Server 2012 R2 come with a bunch of highly useful cmdlets for network adapter management. When you want to investigate Wi-Fi connectivity problems, for example, or try and find out why Wake-On-LAN won’t...
  • Using Finally for Crucial Cleanup Tasks

    PowerShell 2.0 and later In a previous tip we introduced an “acoustic progress bar” that made PowerShell play a sound for as long as it was busy. Here is the code again: # find first available WAV file in Windows folder $WAVPath = Get-ChildItem...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.