December 2008 - 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
  • Stopping and Disabling Services

    You may find that Vista's new Instant Search can sometimes get out of hand and slow down your machine. Temporarily disabling and then stopping the search service is one way to deal with this issue: Set-Service wsearch -startupType Disabled Stop-Service...
  • Using COM Objects to Say "Hi!"

    If you have ever written scripts using VBScript, you probably know COM objects which are DLLs and work like command libraries. You can use COM objects in PowerShell, too. Simply use New-Object and the parameter -COMObject to instantiate the COM library...
  • Order Matters

    Here is a challenge for you. The following code is a simple currency converter. However, when you run it, you'll notice it doesn't convert correctly. Instead, you always get back the result you entered: $number = Read-Host 'Enter amount in...
  • Converting User Input to Date

    PowerShell uses the US/English date format when converting user input to DateTime, which can cause unexpected results if using a different culture. For example, on German systems "1.3.2000" resolves to March 1, 2000. PowerShell can convert this...
  • Casting a Type Without Exception

    Read-Host is a useful cmdlet to use to ask for user input. However, it returns user input always as generic string. Of course, you can always convert the user input to a more specialized type, like DateTime, to calculate time spans: $date = [ DateTime...
  • Downloading Files from the Internet

    You can tap into the wealth of .NET methods easily. Use New-Object to instantiate a new .NET class, and off you go. For example, instantiate an instance of Net.WebClient and you can enable your PowerShell scripts to download files from the Internet: ...
  • Downloads with Progress Bar

    If you'd like to download larger files from the Internet and get a progress indicator, you can load the .NET Visual Basic assemblies, which provide a sophisticated download method with progress bar: [ void ][ Reflection.Assembly ]:: LoadWithPartialName...
  • Outputting Nicely Formatted Dates

    Get-Date provides you with the current date and time. With the -format parameter, you can add style to it. For example, use -format with a lowercase d to just output a short date: Get-Date -Format d You can get a list of format characters directly at...
  • Using Cultures

    Since PowerShell is culture-independent, you can pick any culture you want and use the culture-specific formats. The following script instantiates the Japanese culture, outputting a number as currency first in your current culture and then in the Japanese...
  • Accessing Date Methods

    While Get-Date returns the current date and time, it really returns a DateTime object. You can use this object to find out more about the date or to calculate date and time offsets as it has a number of very useful properties and methods. $date = Get...
  • Filtering Based On File Age

    Every so often, you'll need to filter files by age. Maybe you'll only want to see files that are older than 20 days old and delete them or back them up. So, you need a way to filter file age relative to the current date. Here is a custom filter...
  • Manipulating Arrays Effectively

    While you can add and remove array elements with PowerShell arrays, this is an expensive operation and not recommended with large numbers of elements. Instead, use a .NET ArrayList if you need to dynamically expand and shrink an array at runtime: $array...
  • Multidimensional Arrays

    PowerShell supports two types of multi-dimensional arrays: jagged arrays and true multidimensional arrays. Jagged arrays are normal PowerShell arrays that store arrays as elements. This is very cost-effective storage because dimensions can be of different...
  • Validate User Input

    When you ask users for input you never know what they enter so it is a good idea to validate user input before using it. A great and easy way to do this is using a Do loop together with the -like operator. The following code validates user input to make...
  • Show Battery Status as Prompt

    The PowerShell console prompt can be easily changed by simply changing the prompt function to change the prompt text. If you are working with a notebook, you may want to get a warning when battery power goes low. Use WMI to query the battery status and...
1 2 Next >
Copyright 2012 PowerShell.com. All rights reserved.