I am having trouble running a scheduled job, part of it. The job uses System Center part way through but cannot find the virtual machine in question. However, I can use virtually the same script in a scheduled job, if I dot source it as below (Main is the main function, so the script in essence; I use -filepath):
. Main ‘param1’ ‘param2’ ‘param3’
The problem happens when I try to pass the params with Invoke-Expression
Invoke-Expression “script.ps1 param1 param2 param3”
The user who connects to the System Center VM Server is different than the one who registers the job. However the job works above, and fails partially below. I am able to run the second script perfectly though when I run it interactively.
Why is the inability to connect to VMs in the second case?