My question involves the specific module for PowerCLI, but I'm hoping it involves a more generic issue to PS Jobs. I'm loading a module needed by commands in the job scriptblock but those commands are not recognized, as though the module is not loaded.
I am loading the VMware powerCLI modele before start-job, as follows, but the code in the scriptblock does not recognize that the module is loaded so the get-vm command is not recognized.
import-module VMWare.VimAutomation.core Connect-VIServer -server VIServer01 $NewJob = start-job -scriptblock {Get-VM -server VIServer01 | Select Name, @{N="Cluster";E={Get-Cluster -VM $}},@{N="ESXHost";E={Get-VMHost -VM $}}}
I am familiar with the need to, and methods of, pass parameters from the script to the job script block, but how do I get it to recognize that the module is loaded? Also, if I load the module from within the scriptblock, I get a stack-overflow failure, I guess due to the repeated looped loading of the module.