My script:
$computername=$args[0]
if ($args -eq $null) { $computername = Read-Host "enter computer name" }
Get-ADComputer -Id $computername -Properties * | select name,description
If I pass the argument with the script i.e.:
get-ComputerName.ps1 computer01
it works fine. However if I skip the computer I want it to prompt me but instead I'm getting this error:
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
I cannot figure out how to make it work.