Author Posts

March 31, 2016 at 9:28 pm

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

April 1, 2016 at 1:45 am

Hi,

I tried your first example and it worked. The only time I got same error as you did was when I placed a "-" in Invoke-Command before $a.name:

$a=Get-ADComputer -Filter *
Invoke-Command -$a.name -ScriptBlock { hostname}

Without that " – " this command works for me.

April 4, 2016 at 5:17 pm

Thanks Lauras

But I still have the same error. Actually if I run a subset of $a it'll work.

$a=Get-ADComputer -Filter *
Invoke-Command $a[0..20].name -ScriptBlock { hostname}

April 4, 2016 at 6:00 pm

I think I found the issue.

One computer object contains a space in its name and it caused this weird problem.

Very strange and I don't know how could that computer object was created in the first place.