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
  • Open Many Files With One Command

    To quickly open all files of a kind, such as all text or script files found in a folder, you should try the Open-File function. It will accept a simple pattern, such as *.txt which opens all text files, or a*.ps1,which opens all PowerShell scripts that...
  • Filter by More Than One Criteria

    You should probably use Get-Childitem with its -filter parameter to list specific files because it is much faster than -include. This line will locate all log files recursively in your Windows folder structure: Dir $env:windir -Filter * . log -Recurse...
  • Finding Software Updates

    In Windows Vista/Server 2008, Microsoft introduced many new service and application specific log files. PowerShell can access those with Get-WinEvent. Here is how useful the rich information can be in these logs. The function Get-SoftwareUpdates will...
  • Search for Keywords in Help Files

    You may be surprised that you cannot filter Help texts by keywords: Get-Help Dir | Select-String "File" This will not return anything, even though there is a word called “file” in the Help text (at least in English versions of PowerShell...
  • Kill Specific Excel Instances (or other programs)

    Stop-Process can very easily kill all instances of Excel or another program. So this line will kill all instances of Excel: Stop-Process excel – ErrorAction SilentlyContinue You will need the process ID, which you may not have, to kill specific...
  • 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...
  • 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...
  • 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 ’ ...
  • 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...
  • 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...
  • 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...
  • 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...
  • 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 '...
  • 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...
  • 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."...
« First ... < Previous 58 59 60 61 62 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.