读了上面这个函数,有没有什么疑惑?上面这个PowerShell函数定义了两个参数集,一个参数集名为A,另一个名为B。参数集A只有一个参数$ComputerName,且它是可选的。而参数集B有两个参数$ComputerName和$Credential。如果我们使用参数集A时,输入不需要输入ComputerName这个参数,因为它不是必选的。而如果我们使用参数集B,这个时候就必须要填$ComputerName了。 且看下面的函数调用示例。 复制代码 代码如下: PS> Connect-Somewhere You have chosen A parameter set. PS> Connect-Somewhere -ComputerName test You have chosen A parameter set. PS> Connect-Somewhere -Credential user1 cmdlet Connect-Somewhere at command pipeline position 1 Supply values for the following parameters: ComputerName: NOWMANDATORY! You have chosen B parameter set.