Since version 5.1.9 invoke-command no longer works

I’ve got some scripts that do things and since that version invoke-command in the scripts no longer works with accounts it used to.

example this used to work as my service account (which is a normal user on the remote server), passing the args TargetServer=Server1

param($result,$TargetServer)

Invoke-Command -ComputerName $TargetServer -ScriptBlock {
write-output $env:computername
}

Now it doesn’t (it doesn’t make it in to the scriptblock) gives Invoke-Command: Object reference not set to an instance of an object.

I assume its something to do with this, any ideas? I’ve tried all the different types and none of them work.

looks like maybe “new credentials” works maybe, is that what it used to default to before you could pick the type?

Hi, yes - new credentials was the default impersonation logontype from a couple of minor versions back, before that it was Network but some users couldn’t get that to work depending on their use case. Currently in the UI it selects ‘Network’ as the default when adding a new script task but we may yet change that default again depending on the relative success rates reported with each type.

In general, in-process impersonation in powershell is becoming rather a can of worms and if you can just use the default (local system) it will skip impersonation altogether but that doesn’t work if you need to do something network related.