April 2009 - 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
  • Sort With PS Code

    Sort-Object is a great and versatile cmdlet to sort anything you want. Simply specify the property or properties you want to use for sorting: Dir Length Dir Name A little known fact is that Sort-Object also accepts script blocks to sort different criteria...
  • Displaying First Or Last Elements

    Select-Object can limit results to only the first or last elements. Simply use -first or -last: dir | select-object -first 10 Get-Process | Sort-Object cpu -descending | Select-Object -first 10 Get-Process | Sort-Object cpu -descending | Select-Object...
  • Splitting Text Into Words

    If you ever need to read in a file and split file content into words, there are a couple of gotchas to keep in mind. First off, remember that Get-Content reads files line by line. To apply regular expressions or split operations on the entire text, you...
  • Passing ByRef vs. ByVal

    Usually, when you assign a variable to another variable, its content is copied. Here is an example: $a = "Hello" $b = $a $a = "Hello World" $b As you can see, $b is actually a copy of $a so when you change $a, $b is not changed. If...
  • Ejecting CDs

    PowerShell can still use COM libraries. Simply use New-Object -comObject and provide the COM library name to load it. With this approach, you can do all kinds of unusual things, such as ejecting a CD: $cd_drive = 'E:' $sa = New-Object -comObject...
  • PowerShell Essentials: Get-Member

    Get-Member is the third important basic PowerShell cmdlet as it gives you a documentation of what a command returns. It lists all of the object and property members. By default, you get everything: Dir | Get-Member Note how Get-Member analyzes the returned...
  • PowerShell Essentials: Get-Help

    Get-Help is the second of the three most important PowerShell cmdlets as it retrieves all the Help for any cmdlet. If you just enter Get-Help, you get help for Get-Help itself. Add a cmdlet name, and you get help for that command. Get-Help can even resolve...
  • PowerShell Essentials: Get-Command

    There are only three cmdlets you should know by heart. One is the Get-Command, which can do a lot more than you might think. When called without parameters, it returns all cmdlets available: Get-Command To find cmdlets with a specific purpose, search...
  • Create PowerShell Shortcuts

    If you ever wanted to create shortcut icons on your Desktop, or in your programs menu, to quickly launch PowerShell, here is a way to do it: function CreatePSShortcut { $wshell = New-Object -comObject WScript.Shell $path1 = $wshell . SpecialFolders.Item...
  • Preserving Alias Definitions

    Maybe you have invested some time in creating new aliases, and now you would like to know how to preserve your new aliases so that the next time you launch PowerShell again, they are still there. You have two options. Here is the first one: Write all...
  • Deleting Aliases

    As you may know aliases are shortcuts to other commands. So, you can easily add new aliases like this: Set-Alias edit notepad.exe The next time you enter edit, Notepad will start. However, there seems to be no way to delete aliases. And there is really...
  • Finding PowerShell Background Information

    PowerShell comes with a lot of documentation. One thing you should check out is the QuadFold.rtf file. You should use the following line to find and open the folder with all the PowerShell resources on Vista (Multi-Language): ii "$pshome\Documents...
  • Save (and Load) Current PowerShell Configuration

    PowerShell can be configured in a multitude of ways. Most often, you use Add-PSSnapin to load additional snap-ins with more cmdlets and providers. You should use Export-Console to save your current configuration to file. This is also a great way of looking...
  • Creating Text Files

    PowerShell offers you a multitude of ways to write information to disk. Here's a quick overview. 1. You can use classic redirection: "Hello" > $home \ testfile.txt "Append this" >> $home \ testfile.txt get-content $home...
  • Auto-Documenting Script Variables

    Ever wanted to get a sorted list of all variables used inside a script? Use this function: simply call Get-ScriptVariables and supply a path to your PowerShell script. You will then get back a sorted list of all variable names found in that script: function...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.