Acerbity
Acerbity

Reputation: 527

PowerShell remoting session variable isn't working

I am trying to run a loop using New-PSSession and running as administrator, but I am getting an error.

foreach ($c in $targets) {
    $s = New-PSSession -ComputerName $c -Credential cred
    Invoke-Command -Session $s -ScriptBlock {gci C:\temp} -RunAsAdministrator
}

I am getting the following error:

Invoke-Command : Parameter set cannot be resolved using the specified named parameters.

Upvotes: 0

Views: 346

Answers (1)

Mark Wragg
Mark Wragg

Reputation: 23395

The error occurs because the -Session parameter can't be used at the same time as the -RunAsAdministrator parameter.

Upvotes: 3

Related Questions