LucD, what secret sauce you are using because I am having the same issues ikiris is having whether I use Windows 2008R2, PowerShell 5, PowerCLI 6.3 or Windows 2012 R2, PowerShell 5, PowerCLI 6.3.
I modified the script slightly just to troubleshoot what is going on:
$vcenter1 = 'vcenter1'
$name1 = 'myVM'
$jobcmd = {
$data = $input.getEnumerator()
$data[0]
$data[1]
Import-Module VMware.VimAutomation.Core
$connection = Connect-VIServer $data[0] -User localuser -Password P@ssw0rd
$connection
# Get-VM $data[1]
# Get-VM 'myVM'
Disconnect-VIServer $connection -Confirm:$false -Force:$true
}
$job1 = Start-Job -InputObject @($vcenter1,$name1) -ScriptBlock $jobcmd
while($job1.State -ne 'Completed'){
sleep 5
$job1 = Get-Job -Id $job1.Id
}
Receive-Job -Job $job1
So if I run the script above as is (with Get-VM commented out) the job completes successfully and outputs the two variables and the vCenter connection as expected.
Then I make the following changes:
# $data[0]
# $data[1]
# $connection
Get-VM $data[1]
# Get-VM 'myVM'
Once I run the script it just stays in a "Running" state never completing.
Or if I try it like this it still will not complete.
# $data[0]
# $data[1]
# $connection
# Get-VM $data[1]
Get-VM 'myVM'
Any ideas? This is driving me nuts as it seems like it should be so simple.
Thanks!!!