parameters - Powershell - unable to print value of hash -
i writing simple script more familiar powershell.
this script reads input parameters hash
$states = @($args) $states write-host color $states.color on command-line, set following values
$shape = 'circle'; $color = 'pink'; $size = 'large' i invoke program following command
.\shapes_n_colors.ps1 $shape $size $color and, following output:
circle large pink color i unable figure out why $states.color blank. expecting output "color pink"
i following artical, http://technet.microsoft.com/en-us/library/hh847780.aspx
where going wrong???
not sure start...
first of - don't create hash @ point... @($args) doesn't anything: $args array, , @() useful make sure expression produce array... hash literal @{}.
next: script have no clue names you've used variables passed it. see 3 strings. suggest using param() named parameters (that default positional, calling script wouldn't change much):
param ( $shape, $size, $color ) write-host color $color when try syntax, produce expected results. wait, there's more. ;) run script without need remember param order:
.\shapes_n_colors.ps1 -color white -shape circle -size small not mention complete named parameters you.
Comments
Post a Comment