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
  • Using PowerShell’s Help Window for General Output

    To display text information, you can of course launch notepad.exe, and use the editor to display the text. Displaying text in an editor is not such a good idea, though, if you want to make sure the text cannot be changed. PowerShell comes with a great...
  • Playing Sound in the Background

    If your script takes some time to complete, you may want to play a system sound file. Here is a sample illustrating how this can be done: # find first available WAV file in Windows $WAVPath = Get-ChildItem -Path $env:windir -Filter * . wav -Recurse -ErrorAction...
  • Finding Executable

    Many file extensions are associated with executables. You can then use Invoke-Item to open a document with this executable. Finding out just which executable is responsible for a given file extension is not so trivial, though. You can read the Windows...
  • Splitting Text at Uppercase Letters

    To split a text at each uppercase letter, without having to provide a list of uppercase characters, try this example: $text = ' MapNetworkDriveWithCredential ' [ Char []] $raw = foreach ( $character in $text . ToCharArray ()) { if ([ Char ] :...
  • Finding Uppercase Characters

    If you'd like to find uppercase characters, you could use regular expressions. However, you would then provide a list of uppercase characters to check against. A more flexible way is to use the .NET function IsUpper(). Here is a sample: it scans a...
  • Using Green Checkmarks in Console Output

    In a previous tip you have seen that the PowerShell console supports all characters available in a TrueType font. You just need to convert the character code to the type "Char". Here is a more advanced example that uses splatting to insert a...
  • Using Symbols in Console Output

    Did you know that console output can contain special icons like checkmarks? All you need to do is set the console to a TrueType font like "Consolas". To display special characters, use the decimal or hexadecimal character code, for example:...
  • Test Nested Depth

    When you call a function, PowerShell increases the nest level. When a function calls another function, or script, this will again increase the nest level. Here is a function that can tell you the current nest level of your code: function Test-NestLevel...
  • Aborting Pipeline

    Sometimes you might want to abort a pipeline when a certain condition is met. Here is a creative way of doing this. It works all the way back to PowerShell 2.0. Take a look at the sample code: filter Stop-Pipeline { param ( [ scriptblock ] $condition...
  • "Continue" and Labels

    When you use the "Continue" statement inside a loop, you can skip the remainder of this loop iteration, and continue with the next. "Break" works similar, but aborts a loop and skips all remaining iterations. This raises the question...
  • Get Memory Consumption

    To get a rough understanding how much memory a script takes, or how much memory PowerShell puts aside when you store results in a variable, here is a helper function: #requires -Version 2 $script:last_memory_usage_byte = 0 function Get-MemoryUsage { ...
  • Use Closures to Lock Variables to Script Blocks

    When you use variables inside a script block, the variables are evaluated when you run the script block. To lock variable content, you can create a new "Closure". Once you do this, the script block takes the variable values that were assigned...
  • Mutually Exclusive Parameters (Part 2)

    Mutually exclusive parameters in PowerShell functions use the "ParameterSetName" attribute to assign parameters to different parameter sets (or groups of parameters). A little known fact is that you can assign multiple parameter set names to...
  • Mutual Exclusive Parameters

    Sometimes, PowerShell functions have parameters that should be mutually exclusive: the user should only be able to use either one, not both. To create mutually exclusive parameters, assign them to different parameter sets, and make sure you define a default...
  • Parsing PowerShell Scripts

    If you'd like to create your own color-coded PowerShell scripts, for example formatting them in HTML, here is a sample that gets you started. This sample takes the currently displayed script inside the ISE editor, and asks the PowerShell parser to...
1 2 3 4 5 Next > ... Last »
Copyright 2012 PowerShell.com. All rights reserved.