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
  • Parse an Exact Date

    If you need to parse a date or time information out of raw text, and if the date and time format does not adhere to the standards of your operating system, then you can use a template and define the date and time pattern yourself. Have a look #requires...
  • Faster Array Manipulations

    The "+=" operator is pretty convenient and can add new elements to an array. If you need this more than once, for example in a loop, then this approach is extremely slow, though. Here is a comparison that also shows how you can speed up array...
  • Copy Command History to a Script

    Sometimes you may have played around with the interactive PowerShell and suddenly realized that some of the commands you played with were pretty useful. Wouldn't it be nice to be able to copy the entire command line history to a script? In the PowerShell...
  • Compare Versions

    Ever wanted to compare software versions? If you do it like this, the result is off: PS> '3.12.11.100' -gt '11.1.22.91' True Here, PowerShell does a string comparison. To get the correct result for version numbers, simply hint the type...
  • Cleverly Aborting Endless Loop

    In a previous tip you have seen how an endless loop can be used to continuously monitor things - until PowerShell is closed, or a user presses CTRL+C to abort the script. There is even a way for PowerShell to detect abortion. This way, you can control...
  • Finding Executable Path

    Here is a one liner telling you the exact location of the executable of any running process. The example returns the path to the PowerShell executable you are currently running: PS> (Get-Process -Id $pid).Path C:\WINDOWS\system32\WindowsPowerShell...
  • Doing Things Forever

    If you want PowerShell to run forever, for example in order to continuously ping a site, use a simple endless loop: #requires -Version 2 $ComputerName = ' powershellmagazine.com ' $status = @ { $true = ' is online. ' $false = ' cannot...
  • Switching Keyboard Layout with PowerShell

    Next time you find yourself with a PowerShell console that uses the wrong keyboard layout, keep your fingers off the mouse! Do it with PowerShell (provided you use Windows 8.1/Server 2012 R2 or better): PS> # turn to English layout PS> Set-WinUserLanguageList...
  • Getting Basic Networking Information

    Beginning with Windows 8.1 and Server 2012 R2, the operating system adds a wealth of new cmdlets for OS management. With these cmdlets, it is almost trivial to manage network adapters, for example: # requires Windows 8.1/Server 2012 R2 or better # general...
  • Investigating AD Classes

    Active Directory organizes its content in classes like "user" or "computer". Each class has a predefined set of attributes, like "Name" or "distinguishedName". PowerShell can get in touch with the AD schema, and...
  • Use Ctrl+Space in ISE!

    The PowerShell ISE opens IntelliSense menus frequenty and helps you write code. Sometimes, however, IntelliSense does not pop up automatically, especially when you write DSC configurations. Just remember the CTRL+Space keyboard shortcut. It (re)opens...
  • PowerShell Killing Itself

    If you schedule a script as a scheduled task, or call it externally, and want to make sure the PowerShell process really ends, here is a brute force approach: #requires -Version 2 Stop-Process -Id $Pid -Force This line kills the PowerShell host that is...
  • Converting Arrays to Strings in CSV Exports

    When you export objects to CSV--for example to display them in Excel--arrays won't be output correctly. Here is a simple way that converts arrays to strings prior to outputting them to CSV: #requires -Version 2 $Path = " $env:temp\report.csv...
  • Exploring PowerShell Automatic Variables

    Here is an easy way to get a list of all currently defined variables, their values, and their purpose. #requires -Version 2 Get-Variable | Select-Object -Property Name , Description , Value | Out-GridView If you'd like to set a description for your...
  • Invoking Code Repeatedly

    Sometimes you might want to run some command multiple times until it runs successfully. Here is a function that shows a way to do this: #requires -Version 2 function Invoke-CodeRepeatedly { param ( [ Parameter ( Mandatory = $true )] $ScriptBlock , $RepeatCount...
< Previous 1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.