we found a workaround to this issue,
we are now simply running a powershell script and adding a PowerCLI snap in into the ps script,
powershell script "test_powershell.ps1"
Add-PSSnapIn -Name VMWare.VimAutomation.Core
& "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"
## vcp.txt stores vCenter login password
$vcp = [IO.File]::ReadAllText("C:\Temp\vcp.txt")
#VM target stored in hostname.txt
$hostname = [IO.File]::ReadAllText("C:\Temp\hostname.txt")
Connect-VIServer -Server localhost -WarningAction SilentlyContinue -Protocol https -User Administrator -Password $vcp
#Get powerstate of selected VM and store in a csv file
Get-VM -Name $hostname | Select Powerstate | Export-CSV "C:\Temp\power.csv" -NoTypeInformation
To run this script, place the powershell script above on the vCenter, then run the following as an NSH script job targeted to the vCenter
nexec -i -e cmd /c "echo .|powershell C:\Temp\test_powershell.ps1"
Thanks for posting this Mike.
Running PowerShell / or Powershell based scripts through nexec face this problem because of a limitation in Powershell. Following text which is part of documentation, will solve the problem.
In nutshell, you need to provide flag "-InputFormat none" to Powershell while invoking it from nexec.
powershell scripts when invoked from nsh using nexec command or from an extended object with remote execution
tend to hang; waiting for an input (or atleast an "enter" keystroke) from user even when none is required.
This is seen always with PowerShell v1 and at times with PowerShell v2 as well.
The problem is owing to a bug with powershell when it is invoked using windows APIs as is seen in a problem documented here:
1. Upgrade to Powershell v2 and
2. Use the powershell flag: "-InputFormat none" when invoking powershell for a script.