Reputation: 527
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
Reputation: 23395
The error occurs because the -Session
parameter can't be used at the same time as the -RunAsAdministrator
parameter.
Upvotes: 3