スクリプトブロック(PowerShell 入門) の続きです。
スクリプトブロックではparamによる引数の受け取りが可能です。
PS > $script = { param($a); $a * 3 }
上記は、paramで引数を1つ受け取ります。
このスクリプトブロックは、引数を3倍します。
実行方法は、前回説明したように&演算子を使用して変数名を指定し、その後に引数として渡す値を記述します。
PS > & $script 5 15
もう1つ、$argsによる値の受け取りも可能です。
先ほどのスクリプトブロックを$argsで書き換えてみたのが下記です。
PS > $script = { $args[0] * 3 }
実行方法は、paramのときと同じで
とします。
Theme design by Jelle Druyts
Pick a theme: BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2 BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2009, HIRO
E-mail