I am trying to check the availability size of virtual machines in one region.
The command: Get-AzVMSize -ResourceGroupName RG3 -AvailabilitySetName availabilitysets
However, it appears this error :-
Get-AzVMSize is not recognized as an internal and external command.
Kindly please help. Thanks
We have tried to Getvmsize using below steps:
Make sure to Connected with Azure using Connect-AzAccount.
Then run the following command to list the vm sizes using availability sets name
Get-AzVMSize -ResourceGroupName "myrgname" -AvailabilitySetName "myavsetname"
&
Get-AzVMSize -ResourceGroupName "myrgname" -VMName "myvmname"
OUTPUT SCREENSHOT FOR REFERENCE:-
For more information please refer this MICROSOFT DOCUMENTATION|Get-AzVMSize
Related
I have an account with Azure with different Resource Group and different virtual machine. I would like to know how I can determine which ones are unused. For example check the last date where the virtual machine was started or used by the user using azure cli command.
Please help me out with this...
Easiest would probably to look at the powerstate of a vm.
First list all the vm's and then run a query where you filter out those that are deallocated and belong to a specific resource group:
az vm list -d --query '[?powerState == `VM deallocated` && resourceGroup==`resource_group`]'
For more information on the queries look up 'JMESPath-query' on the Microsoft docs page. Hopefully this helps.
I would like to know how I can determine which ones are unused
Currently, there is no way to do that using cli.
check the last date where the virtual machine was started or used
We can get this information using PowerShell. which follows.
Get data information of deallocated VM using Get-AzVM -VMName xxxx - RgName xxx -Status
# To retrieve the date of VM was Deallocated.
$vmDeallocatedDate = Get-AzVM -VMName <Your VM name> -ResourceGroupName <Your ResourceGroup Name> -Status
$vmDeallocatedDate.Statuses[0].Time
List all the VM's and the timestamp of the action that triggered the Deallocation
Get-AzLog -Status Accepted -DetailedOutput | ?{$_.Authorization.Action -eq "Microsoft.Compute/virtualMachines/deallocate/action"} | fl ResourceId,EventTimestamp
References
Get-AzLog to get VM Deallocate status
Get-AzVM -status to get VM Deallocate status
Is there a way to find Vm uptime? I need to find the VM's which are running more than 6 hours in Vmss using powershell. I am able to get Virtual machines in Vmss and its status(running/deallocated).I tried to run
Get-azurermlog
command to get the event log of vm start time but couldn't find the result.
Vm os-linux,windows.
Can you please guide me to create a powershell script which display vm uptime. Thanks for the help in Advance!!!
Finally! I was able to get the VM uptime from
(Get-AzureRmVmssVM -ResourceGroupName $vmssRg -VMScaleSetName $vmssName -InstanceView -InstanceId $instanceId).Statuses.Time.Date
Using my Google Fu, I am not finding any information on how to troubleshoot a corrupted Azure virtual machine. It has been working fine for almost 8 months and I have had to redeploy it 1-2 before because it would not start.
Any helpful pointers or point me to some troubleshooting steps please.
I did a redeploy of my Azure virtual machine and perhaps did not wait long enough before shooting off the support request and creating this post as I am able to access my VM again. I received the following troubleshooting steps from Azure support professional so I am sharing here in case anyone else runs into these issues:
To over come this issue we can proceed to run a series of PowerShell scripts to force update the actual status of the VM on Azure backend, please follow this process:
To easily complete this, we can launch Azure PowerShell, please go to:
https://github.com/Azure/azure-powershell
Click on “Launch Cloud Shell” button:
On the newly open window, click on “PowerShell” link:
Then you can run the script, as is, line per line:
$vmName = "(Your VM NAME)"
$rgName = "(Your resource Group)"
$vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName
update-AzureRmVM -ResourceGroupName $rgName -VM $vm
This should bring the VM to healthy or ready state.
Please let me know the outcome of the PS command, if successful try to start the VM.
If it still shows as “corrupted” please share with support a screenshot of the error.
Azure has a number of Powershell cmdlets to work with virtual machine scale sets, such as Get-AzureRmVmss. However, I haven't found anything that enables me to determine if a vm scale set is stopped or started. Does anyone know this is possible within Powershell? I suspect it has to be but I'm at a loss to find the support.
Use below PowerShell Cmdlet to get the Status of the Virtual Machine in the Virtual Machine Scale Set(VMSS)
(Get-AzureRmVmssVM -ResourceGroupName {ResourceGroup-Name} -VMScaleSetName {VMSS-Name} -InstanceView -InstanceId "{Instance-ID}").Statuses
Example: (Get-AzureRmVmssVM -ResourceGroupName vmss-rg -VMScaleSetName myvmss -InstanceView -InstanceId "1").Statuses
I have a bizsparkplus subscription. I followed the below link but could not find the capture button:
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-classic-capture-image/#next-steps
Any suggestions?
Until yesterday, I found nothing in Azure's new portal that can help capture an image from a VM,
but today, out of the blue, I found a "Capture" button right inside the VM's Overview tab :) (will appear only for VMs with "Managed Disks")
It is super easy to capture an image (takes like a minute), but you have to connect ssh on the VM first & run this command (which will delete user's home folder) as per this official article:
sudo waagent -deprovision+user -force
then you can use the button.
-- Warning --
Capturing an image from your VM will stop it and mark it as generalized which won't let you start this VM ever again, because being generalized is an irreversible process "by design"! .. the Sh***y thing is, they didn't even put a warning on the button!, so be careful with that!
This feature is not available yet in the new Azure Portal. You have to options : Azure Resource explorer or PowerShell.
Here is an example in powershell. In this example the custom image will be saved in the VM storage account. The vm custom image will be stored in the following location "System/Microsoft.Compute/Images/templates/***.vhd". :
$vmResourceGroup = "iaas-rg";
$vmName = "ubuntu";
$destinationContainerName = "templates";
$vhdNamePrefix = "template";
$sampleOutupTemplatePath = "C:\Templates\ImagesGeneralized\sampleOutputTemplateUbuntu.json";
Login-AzureRmAccount
#Dellocate the VM
Stop-AzureRmVM -ResourceGroupName $vmResourceGroup -Name $vmName
#Generalize the vm
Set-AzureRmVM -ResourceGroupName $vmResourceGroup -Name $vmName -Generalized
# Save the custom vm Image
Save-AzureRmVMImage -ResourceGroupName $vmResourceGroup -VMName $vmName -DestinationContainerName $destinationContainerName -VHDNamePrefix $vhdNamePrefix -Path $sampleOutupTemplatePath
The second option is to use Azure Resource Explorer, you can execute the operations manually * :
*To execute those operations, the mode "read/write" must be selected in Azure Resource Explorer.
Regards,
You can able to capture the classic virtual machines in new portal. There is an option for capturing. attaching is the screenshot.
In case anyone else looking for this topic, I was researching it and found some azure docs here:
Create a managed image of a generalized VM in Azure
which explains generalizing is a one way operation (and why)
and how to deal with that by creating a VM copy first
Create a Windows VM from a specialized disk by using PowerShell
Using the option 3 in the article.