Invoke-command issue with post request script

Anyone any ideas why I might be having an issue with an invoke-command:

invoke-command -computername SERVER -filepath c:\scripts\script.ps1

I get the error:

Invoke-Command: Object reference not set to an instance of an object.

When running as a post request script. It runs fine under any other circumstances it seems. Doesn’t make a difference if I run the CTW service as a domain-admin (for testing). ‘SERVER’ is an AD joined server, I have another invoke-command in the same script that runs fine on a non-AD server.

I can only imagine it is a credentials issue but seems to work outside CTW.

Any ideas?

Hi, in Certify 3.x powershell runs using the 32-bit (x86) version of powershell, could that be the problem? It will also be running as Local System via the background service, not as the interactive user.

Certify v4 (currently in beta) is 64-bit only and will instead invoke a 64-bit powershell process.

Actually thinking about it’s probably because it’s running as Local System, obviously that doesn’t have permission to invoke commands on other servers so you’d need your script to include alternative credentials.

Tried running manually as 32-bit and it seemed ok. Also have changed the service user to local admin and domain admin with no difference either. I misquoted my code earlier, I am passing credentials to it:

invoke-command -computername SERVER -filepath c:\scripts\script.ps1 -credentials $creds

I think its odd that the same command works fine to another server, in the same script, only difference is the other server is not AD joined.

Ah, sorry I didn’t read it properly, I didn’t realise this was already working against another server. It’s definitely machine specific then, I’m no expert but is SERVER allowing WinRM port connections (port 5985?)

It is indeed. It’s working when the script is invoked manually. This is only an issue when called from CTW.

Turns out it was related to being run in 32bit mode, though why I was getting mixed results I’m not sure. Still only seems to need to be 64bit while being run from CTW though.

At any rate, it is working now. Help is much appreciated.

Good to know, so it’s likely that problem will go away when you upgrade to v4. v4 is most likely to be released late next week.