Azure Vmss Vm uptime - azure

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

Related

Finding the last date of the vm using azure cli command

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

Cannot check the size of virtual machines in one region

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

Corrupted Azure Virtual Machine

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 Virtual Machine Scale set - Check if stopped or started via Powershell

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

How to start a azure deallocated vm?

I needed to do a vm backup and I followed this article:
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-linux-capture-image/
So, I executed:
azure vm shutdown vm-1
But now I really need to start the deallocated vm but I don't know how to do it.
When I try to execute this command:
Start-AzureVM -ServiceName "vm-1" -Name "vm-1"
I'm getting this message:
No deployment found in service: 'vm-1'.
And when I try to list all my vm, I don't see vm-1
Any idea of how to start a deallocated vm?
Thanks
Understood your problem. Your VM has been deleted by you and you want it back. Now in order to back your vm you need to make sure you have the vhds of the vm in place.
a. Find out the vhd and convert it to disk(OS Disk and data disk).
b. Use the OS disk's diskname to create a new vm using this powershell-
Set-AzureSubscription -SubscriptionId "xyz" -CurrentStorageAccountName "lmn"
$vm=New-AzureVMConfig -DiskName "OSDiskDiskName" -InstanceSize "InstanceSizeofvm" -Name "VMName"
New-AzureVM -Location "LocationName" -ServiceName "abc" -VNetName "vNetName" -VM $vm -verbose
c. Find out the data disk and attach to the newly created VM.
In case you have deleted the vhds as well, raise a ticket with MS, only they can help you in that case.

Resources