1
我的腳本時提示的$ args:如何丟失
$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 : Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again. At U:\get-ADComputer-assigned-user.ps1:9 char:20 + Get-ADComputer -Id $computername -Properties * | select name,description + ~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Get-ADComputer], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
我想不出如何使其工作。
閱讀[高級功能幫助](https://technet.microsoft.com/en-us/library/hh847806.aspx)並使用強制參數 –