"File not found" Can not use Invoke-SCScriptCommand with anything but cmd.exe + args

641 views Asked by At

I have made a plugin for Microsoft System Center Virtual Machine Manager that executes a powershell script on a host machine through a powershell script called by the c# code of the plugin. (Shellception :P)

Since I allways got an error I decided to test it manually in SCVMM by right clicking on the host and entering powershell.exe or powershellfor executable and export-v -name [name] -path [path] -force - copystate -wait. Now it tells me that there is no such file. Strangely it works with cmd(.exe) and echo test. Shouldn't powershell be installed on Windows Server 2012? Also, if I remotecontroll the host, it works just fine in the console. What am I missing?

1

There are 1 answers

0
MichaelSo On

I figured out that you need to provide the full path when using powershell.exe as executable. The issue is that not all hosts have the system variable PATH that includes the path to the powershell.exe executable.

You can run powershell.exe by providing the full path: %WINDIR%\System32\WindowsPowerShell\v1.0\PowerShell.exe

Or you can run cmd.exe as executable and then to run powershell.exe from this cmd:

executable: cmd.exe parameters: /c powershell.exe echo 1; return 0;