-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-AzHybridBenefit.ps1
23 lines (22 loc) · 1.37 KB
/
Get-AzHybridBenefit.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if((Get-AzContext).Account -eq $null) {
Write-Host "Logging into Az"
Login-AzAccount
}
$subs=Get-AzSubscription #| Out-GridView -PassThru -Title "Subscription selection"
$vms = @()
$vmsizes = @{}
foreach ($sub in $subs) {
$sub | Select-AzSubscription
$vms_status = Get-AzVM -Status
foreach ($loc in ($vms_status | Sort-Object -Property Location -Unique)) {
if(-not $vmsizes[$loc.Location]) {
$vmsizes.Add($loc.Location,(Get-AzVMSize -Location $loc.Location))
}
}
$vms += $vms_status | select-object @{name='subscriptionid';expression={$sub.Id}},@{name='subscriptionname';expression={$sub.Name}}, `
Name,Location,PowerState,@{name='OSType';expression={$_.StorageProfile.OsDisk.OsType}}, `
@{name='Size';expression={$_.HardwareProfile.VmSize}}, LicenseType, `
@{name='CoreCount';expression={$sz=$_.HardwareProfile.VmSize;($vmsizes[$_.Location].Where({$_.Name -eq $sz})).NumberOfCores}}, `
@{name='AHBCoreCount';expression={if($_.StorageProfile.OsDisk.OsType -eq 'Linux') {0} else {$sz=$_.HardwareProfile.VmSize;(@(8,($vmsizes[$_.Location].Where({$_.Name -eq $sz})).NumberOfCores) | Measure -Maximum).Maximum}}}
}
$vms | ConvertTo-Csv -NoTypeInformation | Out-File C:\temp\vm_ahb.csv