Hey guys
I meet a strange issue and can’t explain why?
for example,if I run something like this
$a=Get-ADComputer -Filter *
Invoke-Command $a.name -ScriptBlock { hostname}
it will return an error
Invoke-Command : One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.
At line:1 char:59
- … nding -Expression {Invoke-Command $a.name -ScriptBlock { hostname} }
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- CategoryInfo : InvalidArgument: (System.String:String) [Invoke-Command], ArgumentException
- FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShell.Commands.InvokeCommandCommand
however ,if I add some filter it’ll work.
$computers=get-adcomputer -Filter{operatingsystem -like "*2012 R2*"}
Invoke-Command -ComputerName $b -ScriptBlock { hostname}
I can’t find any difference and when I tried to use trace-command to check, I got some error message from the 1st example
DEBUG: ParameterBinding Information: 0 : CALLING BeginProcessing
DEBUG: ParameterBinding Information: 0 : BIND PIPELINE object to parameters: [Out-Default]
DEBUG: ParameterBinding Information: 0 : PIPELINE object TYPE = [System.Management.Automation.ErrorRecord]
DEBUG: ParameterBinding Information: 0 : RESTORING pipeline parameter’s original values
DEBUG: ParameterBinding Information: 0 : Parameter [InputObject] PIPELINE INPUT ValueFromPipeline NO COERCION
DEBUG: ParameterBinding Information: 0 : BIND arg [One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.] to parameter [InputObject]
DEBUG: ParameterBinding Information: 0 : BIND arg [One or more computer names are not valid. If you are trying to pass a URI, use the -ConnectionUri parameter, or pass URI objects instead of strings.] to param [InputObject] SUCCESSFUL
DEBUG: ParameterBinding Information: 0 : MANDATORY PARAMETER CHECK on cmdlet [Out-Default]
DEBUG: ParameterBinding Information: 0 : BIND NAMED cmd line args [Out-LineOutput]
I din’t specify -inputObject, why it automatically call this parameter?
Cheers
Yuan