Right now I'm viewing the Azure NetApp volume metrics using Azure Portal metrics dashboard.I can see only one month old data. I'm planning to collect this data and save into SQL table. So that I have the history of this data (i.e. more than 30 days). Is there a powershell commands that I can use?
enter image description here
As per Azure NetApp Files: PowerShell One-Liners, you can use Get-AzMetric, provide StartTime and EndTime to get the history of data.
Try the following code snippet taken from the document, for example:
Get-AzResource | Where-Object {$_.ResourceType -like 'Microsoft.NetApp/netAppAccounts/capacityPools/volumes'}
| Get-AzNetAppFilesVolume | Select-Object #{Name='ShortName'; Expression={$_.Name.split('/')[2]}}, #{Name='SizeGiB';
Expression={$_.UsageThreshold / 1024 / 1024 / 1024}},
#{Name='ConsumedGiB';
Expression={[math]::Round($((Get-AzMetric -ResourceId $_.Id -MetricName 'VolumeLogicalSize'
-StartTime $(get-date).AddMinutes(-15) -EndTime $(get-date) -TimeGrain 00:5:00 -WarningAction SilentlyContinue
| Select-Object -ExpandProperty data | Select-Object -ExpandProperty Average) | Measure-Object -average).average / 1024 / 1024 / 1024, 2)}} | Format-Table
You can refer to PowerShell and CLI for Azure NetApp Files and Azure NetApp Files metrics
Related
I need to extract a list of vms in our subscription which also shows the cpu cores each vm has , is there a way of doing this ?
You can use the below PowerShell Script, to pull the list of VM & their respective CPU Cores.
Connect-AzAccount
$vms=get-azvm | select -Property Name,ResourceGroupName,Location
foreach($vm in $vms){
$size = (Get-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name).HardwareProfile.VmSize
$output=Get-AzVMSize -Location $vm.Location|?{$_.Name -eq $size} | select -Property Name,NumberOfCores
Write-Output $vm.Name,$output|Format-Table -AutoSize
}
Here is the sample Output for reference:
I am looking to see if there is a way to check my current azure quota based on input of a VM size? (NOT a VM family)
Sample input:
Standard_D1
Sample output:
Standard DDSv4 Family vCPUs: You have used X/Y available quota
The closest you can get to doing that is through the Usage - List API that #Jim mentioned above. The same is exposed via the Get-AzVMUsage PS cmdlet as well. Note that this cmdlet can only accept a Location parameter and not a VM Size as such.
Get-AzVMUsage -Location "West US 2"
However, if there is a hard requirement for you to fetch the quota for the size you provide, you could combine it with Get-AzComputeResourceSku as follows:
$Location = 'West US 2'
$VMSize = 'Standard_D4d_v4'
# Get the list of VM SKUs for the given location
$SKU = Get-AzComputeResourceSku -Location $Location | where ResourceType -eq "virtualMachines" | select Name,Family
# Figure out the VM Family for the provided size
$VMFamily = ($SKU | where Name -eq $VMSize | select -Property Family).Family
# Fetch the usage
$Usage = Get-AzVMUsage -Location $Location | Where-Object { $_.Name.Value -eq $VMFamily }
Write-Output "$($Usage.Name.LocalizedValue): You have consumed $($Usage.CurrentValue)/$($Usage.Limit) available quota"
# Sample Output
# Standard DDv4 Family vCPUs: You have consumed 16/100 available quota
Also take a look at this article for more information about vCPU quotas.
I am trying to get a list of Azure vm statuses (Allocated,Deallocated). I am able to get it one at a time for a single vm. But when i have a list of VM's or when using wildcard's it fails to get the vm status. Any tips
$ResGrp= "resvmtest"
$action="start"
$vmList = Get-AzVM -ResourceGroupName $ResGrp -Name * -Status
foreach($vm in ($vmList | Select-Object #batch)){
Write-Host $vm.Statuses[1].DisplayStatus
}
I see that you were trying to display the VMs in batches. Unless you have VMs in the thousands, that's not necessary. I also no longer see the Statuses property in Get-AzVM cmdlet. Just try this:
$vmList = Get-AzVM -ResourceGroupName $ResGrp -Status
$vmList | Select-Object Name, PowerState, ProvisioningState # or any other properties you want to display
Either that or I'm not understanding your question.
Just try this :
Get-AzVm -ResourceGroupName <rg name> -Status | Select-Object Name, PowerState
This behaviour appears to have changed. Using the Status parameter now creates an object named Status and within that object.
One way to show the output:
select Name, #{n='New';e={($_.Statuses | where Code -eq 'PowerState/running').DisplayStatus}}
Get-AzAdvisorRecommendation -Category Cost | Where-Object {$_.ImpactedField -eq "Microsoft.Compute/virtualMachines"}
I'm trying to get the Cost Property for Virtual MAchines on "Shut down or resize your virtual machine" but not able to get it similar with the Data shows in portal
Automate the advisor recommendations using PowerShell.
The command seems right. I don't have this Azure advice myself, but I can look for
Get-AzAdvisorRecommendation -Category Cost |
Where-Object {$_.ImpactedField -eq "Microsoft.Network/publicIPAddresses"}
and it gives me the corresponding advice. This should also work with "Microsoft.Compute/virtualMachines".
Are you sure the error is displayed when you omit the pipe?
Get-AzAdvisorRecommendation -Category Cost | Where-Object {$_.ImpactedField -eq "Microsoft.Compute/virtualMachines"} | Select-Object -ExpandProperty ExtendedProperties
I got the required answer with the query..
Thanks Casper!
I need to retrieve the NICs and the associated VMs in Azure
I've run the following Cmdlet:
Get-AzureRmNetworkInterface | Select Name, VirtualMachine
But, it only generate the names of the NICs but when it come to the Virtual Machine it displays Microsoft.Azure.Commands.Network.Models.PSResourceId, as shown in the following figure.
Please advise how to retrieve the actual name of the VM.
Please advise how to retrieve the actual name of the VM.
We could use the select-object to do that. It works correctly for me.
Get-AzureRmNetworkInterface | Select-Object -Property Name, #{Name="VMName";Expression = {$_.VirtualMachine.Id.tostring().substring($_.VirtualMachine.Id.tostring().lastindexof('/')+1)}}
Update : according to the comment
If we want to get the virtual network name we could use the command
Get-AzureRmVirtualNetwork
How to export the result in the same csv file. We could use out-file
Get-AzureRmVirtualNetwork | select Name |out-file $filePath -Append
Get-AzureRmNetworkInterface | Select-Object -Property Name, #{Name="VMName";Expression = {$_.VirtualMachine.Id.tostring().substring($_.VirtualMachine.Id.tostring().lastindexof('/')+1)}} |out-file $filePath -Append