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
  • 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...
  • Use Group-Object to Create Hash Tables

    All PowerShell versions Group-Object can pile objects up, putting objects with the same property together in one pile. This can be quite useful, especially when you ask Group-Object to return hash tables. This would generate a hash table with piles for...
  • Have PowerShell Cheer You Up!

    All PowerShell versions Writing PowerShell code is fun but can be frustrating at times. Here’s a function that makes PowerShell cheer you up. Just turn on your sound, and PowerShell will comment each command with a new remark. function prompt {...
  • Logging What a Script Does

    All PowerShell versions You probably know that in a PowerShell console (not the ISE editor), you can turn on logging: PS> Start-Transcript This will log all entered commands and all command results to a file. Unfortunately it is of limited use when...
  • A Fun Beeping Prompt

    All PowerShell versions If your computer has a sound card, here is a code snippet that will drive your colleagues nuts: function prompt { 1 . .3 | ForEach-Object { $frequency = Get-Random -Minimum 400 -Maximum 10000 $duration = Get-Random -Minimum 100...
  • Returning More Than One Value

    All PowerShell versions If a PowerShell function needs to return more than one value, best practice is to return objects, and store the information in separate object properties. Here is a simple and charming alternative for some scenarios. Simply return...
  • Edit Network “hosts” File

    All PowerShell versions If you find yourself editing the “hosts” file regularly, then it may be tedious to manually open the file in an elevated instance of the Notepad. Since this file can only be edited by Administrators, a normal Notepad...
  • Watch Out With UNC Paths!

    All PowerShell versions Many cmdlets can deal with UNC paths, but using UNC paths can produce flaky scripts. Take a look at this: PS> Test-Path -Path \\127.0.0.1\c$ True It returns true, the UNC path exists. Now change the current drive to a non-Filesystem...
  • Finding AD Users

    All PowerShell versions Searching the AD can be done with simple calls provided you are logged on an Active Directory domain. In a previous tip we illustrated the basic script. Here is an extension that allows you to define a search root (starting point...
  • Finding and Dumping Registry Key Paths

    All PowerShell versions In a previous tip we illustrated how to convert an internal PowerShell path format to a real path. Here is a use case. This code recursively searches through HKEY_CURRENT_USER and dumps all Registry keys that contain the word “powershell”...
  • Correcting PowerShell Paths

    All PowerShell versions Occasionally, you might stumble across strange path formats like this one: Microsoft.PowerShell.Core \ FileSystem :: C:\windows\explorer.exe This is a full PowerShell path name which includes the module name and provider name that...
  • Case-Correct Name Lists

    All PowerShell versions Let’s assume it’s your job to update a list of names. Here is an approach that will make sure that only first letter in a name is capitalized. This approach works with double-names as well: $names = ' some-wILD...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.