Browse by Tags

  • Speed Up Loops

    First, compare these two code samples: $array = 1 . .10000 Measure-Command { for ( $x = 0 ; $x -lt $array . Count ; $x ++ ) { $array [ $x ] } } Measure-Command { $length = $array . Count for ( $x = 0 ; $x -lt $length ; $x ++ ) { $array [ $x ] } } The...
    Filed under: ,
  • Switch Accepts Arrays

    Did you know that the Switch statement can accept arrays? Use this sample to translate numbers into words: PS > switch ( 1 , 5 , 2 , 4 , 3 , 1 ) { 1 { ' one ' } 2 { ' two ' } 3 { ' three ' } 4 { ' four ' } 5 { '...
    Filed under:
  • Check Array Content With Wildcards

    You may know the -contains operator. Try using it to check whether an array contains a specific element: PS > $names = dir $env:windir | Select-Object -ExpandProperty Name PS > $names -contains ' explorer.exe ' True However, -contains does...
    Filed under:
Copyright 2012 PowerShell.com. All rights reserved.