1.How to list the ASG the resource is in
If you want to list all the ASGs in the VM, you need to list them via all the NICs, you could refer to the command below, the $asgnames
is the list of all ASGs, note if different NICs have the same ASG, it will output several times.
$nics = (Get-AzureRmVM -ResourceGroupName "<ResourceGroupName>" -Name "<VM Name>").NetworkProfile.NetworkInterfaces
$nicnames = @()
$asgnames = @()
foreach($nic in $nics){
$a = $nic.Id -split"/"
$nicname = $a[8]
$nicnames += $nicname
$ipconfig = Get-AzureRmResource -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Network/networkInterfaces/ipConfigurations -ResourceName "$nicname/ipconfig1" -ApiVersion 2018-07-01
$asgids = $ipconfig.Properties.applicationSecurityGroups.id
foreach ($asgid in $asgids){
$a = $asgid -split"/"
$asganme = $a[8]
$asgnames += $asganme
}
}
2.The NSG the resource is in
If you want to get NSGs in the VM, you need to get them via all NICs and VNET Subnet.
Get the NSG of the NIC, the $nsgnic
is the NSG:
$nic = Get-AzureRmResource -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Network/networkInterfaces -ResourceName "<NIC name>" -ApiVersion 2018-07-01
$a = $nic.properties.networkSecurityGroup.id -split"/"
$nsgnic = $a[8]
Get the NSG of subnet, the $nsgsub
is the NSG:
$subnet = Get-AzureRmResource -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Network/virtualNetworks/subnets -ResourceName "<Vnet name>/<Subnet name>" -ApiVersion 2018-07-01
$b = $subnet.properties.networkSecurityGroup.id -split"/"
$nsgsub = $a[8]
Then the NSGs of the VM will be the sum
of $nsgnic
and $nsgsub
.
3.The vCPUs and RAM
Try the command below, NumberOfCores
is the vCPUs
, MemoryInMB
is the RAM
, note the RAM in result is in MB
, you could convert it to GB
if necessary.
Get-AzureRmVMSize -ResourceGroupName "<ResourceGroupName>" -VMName "<VMName>"
4.Storage account
If I do not misunderstand, the storage account here you mean the Diagnostics storage account
, try the command below, $storage
is the storage account uri.
$a = Get-AzureRmResource -ResourceGroupName <ResourceGroupName> -ResourceType Microsoft.Compute/virtualMachines -ResourceName "<VM Name>" -ApiVersion 2018-06-01
$storage = $a.properties.diagnosticsProfile.bootDiagnostics.storageUri