October 2010 - 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
  • Finding Methods with Specific Keywords

    As such, .NET Framework is huge and full of stars, and it is not easy to discover interesting methods buried inside of it. You can use the next lines to find all methods with a given keyword: $key = 'Kill' [ System.Diagnostics.Process ]. Assembly...
  • Running Programs as Different User

    If you ever needed to run a program as someone else, you can use Start-Process and supply alternate credentials. When you do that, you should also make sure you specify -LoadUserProfile to load the user profile unless you do not need it: Start-Process...
  • Run Programs Elevated

    If you have User Account Control (UAC) enabled, you may want to run a program elevated. That's easy using Start-Process and the -verb parameter. The next line launches an elevated PowerShell console: Start-Process powershell -verb runas ReTweet this...
  • Launching Programs and Keeping in Touch

    Normally, when you launch a program from inside PowerShell, you will lose contact to it. However, by using Start-Process with the -passthru parameter, you will return the process object, which you can then store and later use to check the execution status...
  • Translating Culture IDs to Country Names

    Have you ever wondered what a specific culture ID means? Here is a nifty function that will translate a culture ID to the full culture name: [ System.Globalization.CultureInfo ]:: GetCultureInfoByIetfLanguageTag ( 'ar-IQ' ) ReTweet this Tip!
  • Listing Available Culture IDs

    Ever needed to get your hands on some specific culture IDs? Here is how you can create a list: [ System.Globalization.CultureInfo ]:: GetCultures ( 'WindowsOnlyCultures' ) Next, you can use a culture to output information formatted in that culture...
  • Clearing Console Content

    When you want to clear the console content, you probably use "cls" or Clear-Host. For some strange reason, the Clear-Host cmdlet really is a function and uses a lot of internal code. Essentially, it clears every single buffer cell one by one...
  • Resetting Console Colors

    While there are two paths for changing the console color, will you be able to revert back to the original settings once you set colors via [System.Console]. Have a look: [ System.Console ]:: BackgroundColor = 'Blue' [ System.Console ]:: ForegroundColor...
  • Changing Console Colors

    Like any other console window, PowerShell has 16 pre-defined colors that you can choose from to set background and foreground color. You can use two different approaches to set the values. Both set the console background color to "Blue": $host...
  • Working with Private Variables

    PowerShell inherits by default variables downstream so subsequent scopes can "see" the parent variables. If you want to turn off variable inheritance altogether, you should use the prefix "private:." This way, variables will only work...
  • Creating "Static" Variables

    Static variables are accessible everywhere. They can be used to collect data from various scopes in one place. You can use a prefix for a variable with "script:" to create a static variable. This example shows a recursive call that runs 10 nest...
  • Understanding Variable Inheritance

    PowerShell variables are inherited downstream by default, not upstream. So any variable you create at a given scope is passed to any code you call from there: $a = 1 Function test { "variable a contains $a" $a = 2 "variable a contains ...
  • Do You Use "Break"?

    "Break" is a special keyword that you can use to exit loops and conditions prematurely. Have a look: Do { $pwd = Read-Host 'Enter your password' If ( $pwd -eq 'topsecret' ) { break } } While ( $true ) As such, the loop would...
  • Change ErrorAction for Your Private Error Handling

    When you handle errors yourself using Trap or try/catch, you should make sure that you set your ErrorActionPreference to "Stop" or specify -ErrorAction Stop for each cmdlet you want to handle. Otherwise, Cmdlet exceptions would be invisible...
  • Deleting Error Records

    In a previous tip, you learned that "Continue" can skip code in a loop. Another scenario for using "Continue" is error handling. Inside your trap, "Continue" deletes the error record and prevents it from bubbling up, so that...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.