欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PowerShell小技巧之同時使用可選強制參數(shù)

 更新時間:2014年09月11日 11:24:17   投稿:hebedich  
本文主要講訴了在腳本函數(shù)中讓可選參數(shù)和強制參數(shù)必須同時使用,有需要的朋友可以參考下。

在下面腳本函數(shù)中讓可選參數(shù)和強制參數(shù)必須同時使用。

下面演示當可選參數(shù)出現(xiàn),也必須使用這個強制參數(shù)。

function Connect-Somewhere
{
 [CmdletBinding(DefaultParameterSetName='A')]
 param
 (
 [Parameter(ParameterSetName='A',Mandatory=$false)]
 [Parameter(ParameterSetName='B',Mandatory=$true)]
 $ComputerName,
 [Parameter(ParameterSetName='B',Mandatory=$false)]
 $Credential
 )
 $chosen = $PSCmdlet.ParameterSetName
 "You have chosen $chosen parameter set."
}
 
# -Computername is optional
Connect-Somewhere
# here, -Computername is mandatory
Connect-Somewhere -Credential test

支持所有PS版本

相關文章

最新評論