azure vms creating failed - azure

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:

Related

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 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

Azure ARM Scale Set - deploy and update solution

I have been browsing web regarding Azure Scale Set service and I have been able to find a lot of resources connected to scaling and deploying of scale set, however I was not able to find any information regarding deployment and update of the solutions deployed to the machines within scale set. Please what is the best practise when I want to host e.g. a web solution within scale set? How should I perform deployment and updates?
Thank you in advance.
It will depend on how you configure the scale set to be a web solution to begin with...
For example, if you create the VMSS with a template and then configured the VMSS with a custom script extension, then you could run the template deployment again and update the script.
If you used DSC (windows vm) then you could just update the artifacts source and DSC will do the update while the VMs are running.
If you want to use PowerShell for deployment to the Scale Set.
$customConfig = #{
"fileUris" = #("https://$storageAccountName.blob.core.windows.net/scripts/script.ps1");
"commandToExecute" = "PowerShell -ExecutionPolicy Unrestricted .\script.ps1";
};
$vmss = Get-AzureRmVmss -ResourceGroupName $resourceGroup -VMScaleSetName $vmssname
Add-AzureRmVmssExtension -VirtualMachineScaleSet $vmss -Publisher Microsoft.Compute -Type CustomScriptExtension -TypeHandlerVersion 2.0 -Name "runscript" -Setting $customConfig
# Send the new config to Azure
Update-AzureRmVmss -ResourceGroupName $resourceGroup -Name "$vmssname" -VirtualMachineScaleSet $vmss

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