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
  • Invoking Different Code Based on Parameter Value

    Here is a simple concept using an action parameter with a number of choices. Each choice refers to a script block that would be executed then. #requires -Version 2 function Invoke-SomeAction { param ( [ String ] [ Parameter ( Mandatory = $true )] [ ValidateSet...
  • Finding Script Block Variables

    Script blocks define a PowerShell code without executing it. The easiest way of defining script blocks is placing code into braces. Script blocks sport a number of advanced features to examine the code they embrace. One is direct access to the abstract...
  • Getting Installed Software Remotely

    In a previous tip we introduced the Get-Software function that was able to retrieve installed software from local computers. If you have enabled PowerShell remoting on remote systems (enabled by default on Windows Server 2012 and better), and if you have...
  • Reading Installed Software from Registry

    Here is a very quick way of finding installed software. The Get-Software function reads both the 32- and 64-bit locations for software installed for all users. #requires -Version 1 function Get-Software { param ( [ string ] $DisplayName = ' * '...
  • Display Message Box Dialog

    PowerShell is console-based, but sometimes it would be nice to add some simple dialogs. Here is a function called Show-MessageBox that can display all kinds of standard message boxes and comes with IntelliSense for parameters: #requires -Version 2 Add...
  • Use Server-Side Filtering When Possible

    When you retrieve information across a network, always make sure you use client-side techniques like Where-Object as a last resort. Server-side filtering is much more efficient. For example, when you are trying to find users with a defined mail address...
  • Turning Lists of Numbers Into Useful Lists

    PowerShell features the ".." operator which produces lists of numbers. With the -join operator, you can convert these to almost anything you want, like comma-separated values. And when you convert the numbers to characters, you can turn ASCII...
  • Checking for AC Power

    Ask WMI to find out whether your notebook is connected to AC: #requires -Version 1 $battery = Get-WmiObject -Class Win32_Battery | Select-Object -First 1 $noAC = $battery -ne $null -and $battery . BatteryStatus -eq 1 if ( $noAC ) { ' On battery power...
  • Creating Enumerations

    PowerShell 5.0 added the capabilities to define enumerations but in older PowerShell versions, you can create enumerations too, simply by compiling the appropriate C# code: #requires -Version 2 $code = @" public enum Cities { NewYork, Hamburg, HongKong...
  • Crazy Prompt Function

    The built-in "prompt" function is invoked whenever PowerShell completed interactive input, and you can use it to change the way your prompt looks like. You can also abuse it. If you smuggle this version of a prompt function into your colleagues...
  • Conversation with PowerShell

    Today's tip is using the programmable CommandNotFoundHandler to have PowerShell talk with you once you enter an unknown command: $ExecutionContext . InvokeCommand . CommandNotFoundAction = { param ( [ string ] $commandName , [ System.Management.Automation...
  • Finding Operating System Version

    One of the easiest ways of getting your operating system version is this one line of code: PS> [Environment]::OSVersion Platform ServicePack Version VersionString -------- ----------- ------- ------------- Win32NT Service Pack 1 6.1.7601.65536 Microsoft...
  • Why Some Errors Aren't Caught

    When you receive a red error message from PowerShell, you can always encapsulate the code in a try…catch block and handle the error yourself: try { 1 / 0 } catch { Write-Warning "Something crazy happened: $_" } However, some errors, especially...
  • Using Paths in Prompts

    The default PowerShell prompt displays the current location. When you are deep inside nested folders, this steals room for your actual input, and you may have to scroll a lot. There are plenty of ways how to deal with it. Here are two alternate prompt...
  • Help Make PowerShell a Better Place!

    Rather than ranting about things that don't work as expected, or things you feel are missing, be constructive! The PowerShell team takes great efforts to improve and expand PowerShell. All that's needed is your feedback. So there is a one-stop...
« First ... < Previous 3 4 5 6 7 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.