This is about running an "azure command" as a background job.
I've been dealing with this for a week already.
If I run this command:
Code: Select all
Get-AzureRMVm | where{($_.ResourceGroupName -eq $ResourceGroup) -and ($_.name -eq $vmname)} -ErrorAction Stop
But when I run it like this:
Code: Select all
$path = "\profile.json"
$deploy = {
Param ($path,
$ResourceGroup,
$VMName)
Import-AzureRmContext -Path $path | out-null
Get-AzureRMVm | where{($_.ResourceGroupName -eq $ResourceGroup) -and ($_.name -eq $vmname)} -ErrorAction Stop
}
Save-AzureRmProfile -Path $path -force
$job = Start-Job -ScriptBlock $deploy -ArgumentList $path, $ResourceGroup, $VMName
Wait-Job $job
$AllVMs = Receive-Job $job
Anybody have any idea why and most importantly, how to solve it?