「PowerShell」引数と戻り値あり関数のサンプル

書式
function 関数名($引数…) {処理コード}
関数を呼び出します
関数名 値1 値2…

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function funcA($cftA,$cftB){
$result = $cftA * $cftB
return $result
}
$cft = funcA 8 10
Write-Host $cft
function funcA($cftA,$cftB){ $result = $cftA * $cftB return $result } $cft = funcA 8 10 Write-Host $cft
function funcA($cftA,$cftB){
    $result = $cftA * $cftB
    return $result
}
$cft = funcA 8 10
Write-Host $cft

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
PS C:\study\powershell> .\test.ps1
80
PS C:\study\powershell> .\test.ps1 80
PS C:\study\powershell> .\test.ps1
80

 

PowerShell

Posted by arkgame