How to start a azure deallocated vm? - azure

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.

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

azure vms creating failed

I created 2 VMs, one is the domain controller, another is for hosting the applications, then I created 2 images from these VMs by following this article. But now I cannot create VM from the images, even manually create the image from the Azure portal. what I missed?
Here is the code looks like:
foreach($a in $arr){
$a = $a.Trim()
New-AzVM -ResourceGroupName $env:groupName -Name dc$a -ImageName $env:dcImageName -Location $env:location -VirtualNetworkName vNet$a -SubnetName subnet$a -SecurityGroupName ngs$a -PublicIpAddressName publicIp$a -OpenPorts 3389 -Credential $cred
New-AzVM -ResourceGroupName $env:groupName -Name app$a -ImageName $env:appImageName -Location $env:location -VirtualNetworkName vNet$a -SubnetName subnet$a -SecurityGroupName ngs$a -PublicIpAddressName publicIp$a -OpenPorts 3389 -Credential $cred
}
The error is:
##[error]Long running operation failed with status 'Failed'. Additional Info:'OS Provisioning for VM 'dclab1' did not finish in the allotted time. The VM may still finish provisioning successfully. Please check provisioning state later. Also, make sure the image has been properly prepared (generalized).
Best Regards,
Sue.
Currently, I've been given up this solution, I use the snapshot of VHD to create VM instead of creating VM from the images.
From the error message, It seems that your image is not properly prepared (generalized).
Time might be the issue. You could try to generalize the Windows VM using SysprepSysprep. Normally it takes 10 - 15 minutes, you should wait for enough time for the Sysprep. When the status is changed to stop in the Azure portal, you could deallocate and mark the VM as generalized.
Also, make sure you have selectd each of the steps during the generalization process:

Attaching restored OS disk to existing VM

I have one VM with a daily backup scheduled. Today I deleted a file in that VM and changed some configuration. I restored yesterday's data disk from my recovery service vault and changed the names of the recovered data disk.
Now I want to attach yesterday's restored backup to my existing VM. Is it possible?
If not then suppose I delete my VM but I keep its network interface card. I can create a new VM from restored VHDs using ARM templates but how can I assign an existing NIC to my new VM?
Also, I have added this VM to my domain controller. If I recreate the VM, do I need to add the new VM to the domain controller or will it work normally?
Now I want to attach yesterday's restored backup to my existing VM. is
it possible?
Yes, we can attach this restore disk to your existing VM, then we can find the disk in your existing VM.
I delete VM but I keep network interface card for the VM, now I can
create VM from restored VHD's using ARM templates but how to assign
exiting NIC in the new VM?
Yes, we can use PowerShell to create a VM with existing NIC and VHD, here is an example:
$rgname = "jason-newgroup"
$loc = "japaneast"
$vmsize = "Standard_DS1_v2"
$vmname = "jason-newtest2"
$vm = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize
$nic = Get-AzureRmNetworkInterface -Name "NICname" -ResourceGroupName $rgname
$nicId = $nic.Id
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nicId
$osDiskName = "jason-newtest"
$osDiskVhdUri = "https://jasonnewgroupdisks912.blob.core.windows.net/vhds/jason-newtest201681285042.vhd"
$vm = Set-AzureRmVMOSDisk -VM $vm -VhdUri $osDiskVhdUri -name $osDiskName -CreateOption attach -Windows
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $vm
if I recreate the VM do I need to add new VM to domain controller or
will it work normally?
Yes, the new create VM (restore) will add to the domain controller, we don't need to add the VM to domain controller again.

How to increase size of OS disk in Windows Azure using Powershell

I want to increase size of OS disk in Windows Azure using Powershell or any other tool. Please help
Regards
Umair
Resize the OS drive
Open your Powershell ISE or Powershell window in administrative mode and follow the steps below:
Sign-in to your Microsoft Azure account in resource management mode and select your subscription as follows:
Login-AzureRmAccount
Select-AzureRmSubscription –SubscriptionName 'my-subscription-name'
Set your resource group name and VM name as follows:
$rgName = 'my-resource-group-name'
$vmName = 'my-vm-name'
Obtain a reference to your VM as follows:
$vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName
Stop the VM before resizing the disk as follows:
Stop-AzureRmVM -ResourceGroupName $rgName -Name $vmName
And here comes the moment we’ve been waiting for! Set the size of the OS disk to the desired value and update the VM as follows:
$vm.StorageProfile.OSDisk.DiskSizeGB = 1023
Update-AzureRmVM -ResourceGroupName $rgName -VM $vm
The new size should be greater than the existing disk size. The maximum allowed is 1023 GB.
Updating the VM may take a few seconds. Once the command finishes executing, restart the VM as follows:
Start-AzureRmVM -ResourceGroupName $rgName -Name $vmName
And that’s it! Now RDP into the VM, open Computer Management (or Disk Management) and expand the drive using the newly allocated space.
pasted from: https://learn.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-expand-os-disk
i have done this by using below command on windows azure powershell latest version. Please note old version of powershell doesnot support this command .
Update-AzureDisk -DiskName [Disk-Name] -Label [DiskLabel]-ResizedSizeInGB 1020

Why does New-AzureReservedIP return ResourceNotFound: No deployments were found?

I have a cloud service that has two VMs in it. I'm trying to follow the steps listed in this article to reserve my cloud service's IP address.
Login-AzureRmAccount -TenantId <my tenant id>
Set-AzureRmContext -SubscriptionId <my subscription id>
New-AzureReservedIP -ReservedIPName myname -Location "Central US" -ServiceName mycloudservicename
I always get this error:
New-AzureReservedIP : ResourceNotFound: No deployments were found.
The VMs were created in the new portal but are classic mode. I'm not sure if that is somehow my problem. I've tried other combinations of cmdlets to add accounts or set subscription but nothing helps.
Any ideas?
I was fighting like 30 minutes with this. I'm not very sure why this was happening but I think was an error selecting the subscription. Last time it worked like this:
Close Azure Power Shell and Open it again.
Listed my subscriptions with: "Get-AzureSubscription" (Make sure you are logged in).
Now I can see the exact Subscription ID and use "Select-AzureSubscription -SubscriptionId XXXXXXXX"
After that the command worked.
New-AzureReservedIP -ReservedIPName "myname" -Location "South Central US" -ServiceName "myservice"
Hope it helps.
If your VMs were created in the new portal, you need to switch to the Resource Manager model, New-AzureReservedIP is only used for the classic portal services, so it prompted ResourceNotFound: No deployments were found error.
There is no AzureReservedIP in Azure RM cmdlets. In the new portal, the IP address is associated to network interface.If you want to set your VMip to be static,run the following command:
$nic=Get-AzureRmNetworkInterface -ResourceGroupName JohTest -Name johtestvm250
$nic.IpConfigurations[0].PrivateIpAllocationMethod="Static"
$nic.IpConfigurations[0].PrivateIpAddress = "10.2.0.4"
Set-AzureRmNetworkInterface -NetworkInterface $nic
If you dont know the networkinterface in your RG, run the command to see:
Get-AzureRmNetworkInterface -ResourceGroupName JohTest
More information here

Resources