March 2011 - 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
  • Print All PDF Files in a Folder

    Try this one-liner if you need to print out all PDF documents you have stored in one folder: Dir c:\myfolder\ * . pdf | Foreach-Object { Start-Process -FilePath $_ . FullName –Verb Print } ReTweet this Tip!
  • Be Careful With Strict-Mode!

    You will discover that PowerShell is production-oriented. So, if you specify object properties that do not exist, you will simply get back "nothing": $Host . LetsSee This is bad because you will not get a warning if you mistype a property name...
  • Resolve IP-Addresses

    This one-liner accepts one or more IP-addresses and will try to resolve the address. If DNS returns valid information, you will receive the host name and aliases. If not, you will get a warning with the cause: ' 127.0.0.1 ' , ' 127.0.0.2 '...
  • Filter PowerShell Results Fast and Text-Based

    Take a look at this simple filter called grep: filter grep ( $keyword ) { if ( ( $_ | Out-String ) -like "*$keyword*" ) { $_ } } And here are some samples showing how easy it is to filter results using plain text keywords: PS > Get-Service...
  • Analyzing Windows Launch Time

    Beginning with Windows Vista/Server 2008, you can get rich information about your machine from the new additional application and service logs that are accessible by Get-WinEvent. You should have a look at the function Get-WindowsLaunch. It will tell...
  • Wait For a Program to Finish

    You should use Start-Process and its -Wait parameter if you want to force PowerShell to wait for a program to finish before it continues: Start-Process notepad -Wait This will cause PowerShell to suspend until you close Notepad. You should access the...
  • Find True Property Names

    Sometimes, the column names you see when you run cmdlets do not really correspond with the true object property names. For example, Get-Process will create a column named "CPU(s)," and Get-EventLog will display a column named "Time."...
  • Learn About Operators

    Operators are an important part of the PowerShell language. Try this to learn more about them: Help operators This will list all the different kinds of operators. For example, you will need comparison operators if you want to create conditions. You can...
  • Use Hash Tables To Convert Numeric Return Values

    You can use Hash Tables to translate individual return values to clear text. This example shows you how to convert return codes 0 and 5 to some clear text representation: $cleartext = @ { 0 = ‘ success ’ 5 = ‘ access denied ’ ...
  • Split Special Characters

    PowerShell’s new –split operator can split text into parts. Usually, you will submit a delimiter character to tell –split where to split: PS > "1,2,3,4" -split "," 1 2 3 4 However, you can also submit a script...
  • Encrypt Files With EFS

    You should first access the file using Get-Item to encrypt a file with EFS: $file = Get-Item c:\somefile.txt Next, call its Encrypt() method. Provided that EFS is available on your system, the file will be encrypted, and in Windows Explorer, the file...
  • Output Data in Color

    When you pipe results to Write-Host to output them in color, you may be in for a surprise: Get-Process | Write-Host -ForegroundColor Yellow The result is colorized, but Write-Host has converted the processes into very simplistic string representations...
  • Use Sort-Object With Better DataTypes

    This line of code will sort system DLLs based on file version. However, it turns out that it sorts incorrectly: dir $env:windir\system32 -filter * . dll | ` Select-Object -ExpandProperty VersionInfo | ` Select-Object FileName , ProductVersion | Sort-Object...
  • Determining Service Start Mode

    By using WMI, you can enumerate the start mode that you want your services to use. To get a list of all services, try this: Get-WMIObject Win32_Service | Select-Object Name, StartMode If you want to find out the start mode of one specific service, try...
  • Changing Service Startmode

    You can use WMI like this if you want to change a service start mode: ([ wmi ] 'Win32_Service.Name="Spooler"' ). ChangeStartMode ( 'Automatic' ). ReturnValue ([ wmi ] 'Win32_Service.Name="Spooler"' ). ChangeStartMode...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.