「PowerShell」デフォルト引数を利用する関数のサンプル

書式
function 関数名($引数1=値,$引数2=値2…){処理コード}
変数名 = 関数名 値
関数の引数の一部にデフォルト引数を利用します
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function funA($cftA=1,$cftB=100,$cftC=15){
$result = $cftA + $cftB + $cftC
return $result
}
$res = funA 10
Write-Host $res
function funA($cftA=1,$cftB=100,$cftC=15){ $result = $cftA + $cftB + $cftC return $result } $res = funA 10 Write-Host $res
function funA($cftA=1,$cftB=100,$cftC=15){
    $result = $cftA + $cftB + $cftC
    return $result
}
$res = funA 10
Write-Host $res

実行結果
PS C:\study\powershell> .\test.ps1
125

PowerShell

Posted by arkgame