正如馬特說,我們可以利用這個腳本PS拿到VM數組中:
PS C:\> $b
GROUP
GROUP1
PS C:\> (Get-AzureRmVm | Where-Object {$b -contains $_.ResourceGroupName})
ResourceGroupName Name Location VmSize OsType NIC ProvisioningState
----------------- ---- -------- ------ ------ --- -----------------
GROUP vm1 eastus Standard_A1 Linux vm1619 Succeeded
GROUP vm2 eastus Standard_A1 Linux vm2346 Succeeded
GROUP1 vm3 eastus Standard_A1 Linux vm3554 Succeeded
PS C:\> $vms = (Get-AzureRmVm | Where-Object {$b -contains $_.ResourceGroupName})
PS C:\> $vms
ResourceGroupName Name Location VmSize OsType NIC ProvisioningState
----------------- ---- -------- ------ ------ --- -----------------
GROUP vm1 eastus Standard_A1 Linux vm1619 Succeeded
GROUP vm2 eastus Standard_A1 Linux vm2346 Succeeded
GROUP1 vm3 eastus Standard_A1 Linux vm3554 Succeeded
'$虛擬機=(GET-AzureRmVm |位置對象{$ _ ResourceGroupName -in $ RGS} )' – Matt