【发布时间】:2016-04-26 08:17:21
【问题描述】:
我的脚本:
$computername=$args[0]
if ($args -eq $null) { $computername = Read-Host "enter computer name" }
Get-ADComputer -Id $computername -Properties * | select name,description
如果我通过脚本传递参数,即:
get-ComputerName.ps1 computer01
它工作正常。但是,如果我跳过计算机,我希望它提示我,但我会收到此错误:
Get-ADComputer:无法验证参数“身份”上的参数。论据
一片空白。为参数提供一个有效值,然后尝试运行
再次命令。
在 U:\get-ADComputer-assigned-user.ps1:9 char:20
+ 获取 ADComputer -Id $computername -Properties * |选择名称,描述
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Get-ADComputer], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
我不知道如何使它工作。
【问题讨论】:
-
阅读advanced function help并使用强制参数
标签: powershell args