Can anyone explain why I’m getting ‘Object reference not set to an instance of an object’? The script is supposed to execute a batch file on a number of remote machines but I get the aforementioned error. I’ve verified the file gets there and arguments are passing through.
I have a couple of thoughts here. First, do you need to authenticate at any point while your script is running? (It may be in there, but I’m not seeing it).
Second - do you have any windows event logs for the remote machine? If everything is passing through then it may be failing to run the file for some reason. You can also add lines to your batch files to write to the event log as well, if you’re not seeing anything.
Let me know if this points you in the right direction.
What I would also do is to check and see if the files I try to copy exist, and if so then try and execute them. Lastly, if it’s still not working I’d add in the additional logging to try and find out what exactly is going on.
Just for fun - have you tried running this invoke-command as another user? That may solve the problem outright. Adding a -credential (get-credential) on your invoke-command could potentially do the trick.
I’ve just re-wrote script to accept .ps1 rather than .bat; I can get a .ps1 to do most of the same things as .bat (and most times more ). I just wanted to put it out there to make sure it wasn’t something obvious I was missing…