Here’s a question we received recently about using PowerShell inside Opalis workflows that I thought might be useful for everyone:
I’ve got a PowerShell script that I’m executing – it’s the sum total of three lines and is about as good as I get when it comes to PowerShell.
My PowerShell is this:
$cluster=get-vmhostcluster -name "mycluster.mydomain.com" -vmmserver myserver.mydomain.com
$vmhosts=get-vmhost -vmhostcluster $cluster | select -property Name
This script executes on the Opalis server using the Run .Net script object, I’ve got the VMM admin console installed and it works fine. It basically publishes out one parameter (vmhosts).
The curious thing is that if I execute this in the testing console everything works fine. The script executes and passes the right data through to the next action and I can use the data exactly as I want. If I check the script in and try to run it, I get epic fail. I get an error message which says “Cannot validate argument on parameter VMHostCluster. The argument is null”. This is obviously coming from the last line in the script when it’s trying to use the object that it got in the second line. I don’t know if this error is coming from PowerShell or if it’s coming from Opalis, but I don’t know why the script is executing perfectly in the testing console but not when I try to actually run it.
And here’s the answer:
When you run a workflow on the Action Server it uses the Service Account for the Opalis Action Service (unless you user object-level impersonation). When you run a workflow in the Testing Console it runs using the credentials you are logged in with. That might explain the difference you are seeing.