2017-02-08 46 views
1

我想獲得的所有虛擬機的存在,其中VM資源組的名稱是$ RGS陣列Azure的PowerShell的:其中財產在Array

$rgs = (Get-AzureRMResourceGroup | Where-Object { $_.Tags.Keys -eq 'FindMe' }).ResourceGroupName 
$vms = (Get-AzureRmVm | Where-Object {$_.ResourceGroupName (Enter logic here) }) 
foreach ($vm in $vms) 
{ 
    Write-Host $vm 
} 

這可能在獲取對象?或者更好的方式來創建嵌套循環?

+3

'$虛擬機=(GET-AzureRmVm |位置對象{$ _ ResourceGroupName -in $ RGS} )' – Matt

回答

0

正如馬特說,我們可以利用這個腳本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 
+0

只需檢查以查看提供的信息是否有幫助。如果您需要進一步的幫助,請告訴我。 –