I am trying to get a list of all Virtual Machine Instances within all Scale Sets of a subscription using powershell.
I have been able to list out all the Scalesets by using the code below, but I would like to show all the Virtual Machine instances within each one.
$azureSubs = Get-AzSubscription -TenantID xxxxxxxxxxxxxxxxx
$azureSubs | ForEach-Object {Select-AzSubscription $_ | Out-Null; Get-AzVMss -WarningAction SilentlyContinue} | Export-Csv -Path "c:\Azure\VirtualMachinesScaleSet.csv" -NoTypeInformation
Can anyone suggest anything to help.
You could use the Get-AzVmssVM
command, try the script below in each subscription.
$vmss = Get-AzVmss
$instances = foreach($item in $vmss){
Get-AzVmssVM -ResourceGroupName $item.ResourceGroupName -VMScaleSetName $item.Name
}
$instances | Export-Csv -Path "C:\Users\joyw\Desktop\ins.csv"
Update:
For multiple subscriptions in a tenant,try the script below.
$subs = Get-AzSubscription -TenantId "<tenant-id>"
$instances = @()
foreach($sub in $subs){
Set-AzContext -SubscriptionId $sub.Id
$vmss = Get-AzVmss
foreach($item in $vmss){
$vms = Get-AzVmssVM -ResourceGroupName $item.ResourceGroupName -VMScaleSetName $item.Name
$instances += $vms
}
}
$instances | Export-Csv -Path "C:\Users\Administrator\Desktop\ins.csv"
You can use Get-AzureRmVM to get the hostname and instance id:
PS > Get-AzureRmVM -ResourceGroupName "vmss" -VMScaleSetName "vmss"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With