Idera nSoftware Compellent

Power Tips

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
  • Type Accelerators

    PowerShell has a few shortcuts for popular .NET types like [WMI], [ADSI] or [Int]. You should read the FullName property if you'd like to know the underlying full type name: [ WMI ]. FullName ReTweet this Tip!
  • Comparing Versions

    When you compare version strings, PowerShell will use alphanumeric algorithms, which may lead to confusing results: '3.4.22.12' -gt '22.1.4.34' True You should convert the strings to a System.Version type to compare version strings right...
  • View Object Inheritance

    A hidden object property called "PSTypeNames" will tell you the object type as well as the inherited chain: ( Get-WMIObject Win32_BIOS). PSTypeNames In contrast to GetType(), this property will work for all objects, including COM objects. The...
  • Using Scripts to Validate Input

    For tricky validation checks, you should use arbitrary PowerShell code to validate. The function Copy-OldFiles will only accept files (no folders) and those that are older (in days) than specified in -Days: function Copy-OldFiles { param ( $Days = 30...
  • Restrict Input to Numeric Ranges

    Let's say you'd like to set the PowerShell console cursor size. This size must be a number between 0 and 100. The following template will validate that the user cannot specify an argument outside the allowed range: function Set-CursorSize { param...
  • Converting Object Types

    Once you know the name of an object type, you can use that type for conversion. The next line converts a string into a date-time type: [ DateTime ] '4.5.2010' You should note that conversion uses the culture-neutral date format which happens to...
  • Finding Object Types with Powershell

    Anything in PowerShell is an object. You can use GetType() to get the object type: 'Hallo' . GetType (). FullName (4). GetType (). FullName (2.6). GetType (). FullName ( Get-Date ). GetType (). FullName ReTweet this Tip!
  • Validate Input Using Regular Expressions

    Function parameters can be validated using standard regular expressions. For example, the next template function accepts only valid Knowledge Base article numbers beginning with "KB" and a six- digit number: function Get-KnowledgeBaseArticle...
  • Limiting String Input Length

    If a function parameter should receive a string of a given length only, you should use the following validation attribute. In the example, it limits filenames to eight characters: function Get-FileName { param ( [ValidateLength(1,8)] [ String ] $FileName...
  • Limiting Number of Arguments

    Function parameters can receive multiple values when they accept arrays. You should use this template to limit the number of values acceptable: function Add-Users { param ( [ValidateCount(1,3)] [ String []] $UserName ) $UserName - ForEach-Object { "Adding...
  • Defining Alias Properties

    Your functions can have properties with built-in alias names. The user can then either use the descriptive "long" name or its short and convenient alias name: function Get-BIOSInfo { param ( [Alias( "CN" )] $ComputerName = "."...
  • Validate Set of Inputs

    If you need to limit a function parameter to only a set of allowed choices, you should use the next example: function Get - 24hEventLogEntries { param ( [ String ] [ValidateSet( 'System' , 'Application' )] $LogName = 'System' ...
  • Finding Cmdlets With a Given Parameter

    Finding cmdlets by name is easy: Get-Command * service * -commandType Cmdlet But how can you list all cmdlets that support a given parameter? If you’d like to see all cmdlets with a -List parameter? The easiest way is to use Get-Help with the parameter...
  • Removing All Internet Explorer Cookies

    You'd probably like to regularly clean your machine and remove all cookies set by Web sites you may have visited? Here is how: Dir ([ Environment ]:: GetFolderPath ( "Cookies" )) | del -whatif You will want to make sure you remove the -whatif...
  • Listing Internet Explorer Cookies

    Have you ever wanted to find out who stored your information while you were surfing the Web? Check out your cookies folder: Dir ([ Environment ]:: GetFolderPath ( "Cookies" )) You should try this to open that folder in your Explorer: Explorer...
1 2 3 4 5 Next > ... Last »
Copyright 2010 PowerShell.com. All rights reserved.