So I have been trying to create a VM from Linux VHD and getting this error.
Following this
https://pebkac.io/2016/10/mikrotik-chr-in-azure-part-two/
Dinesh has resolved the problem, per comments on this.
It seems that the NIC creation may have been long running.
According to your error, please ensure NIC Interface is created successful.
$InterfaceName = "nic-chr-test"
$Interface = Get-AzureRmNetworkInterface -Name $InterfaceName -ResourceGroupName
You could the result of $Interface, if this is NULL, please create NIC firstly.
Also, you could try to use this template or scripts in this
template.
[Worked for me , needed to add the network interface to vm. Here is the cmdlet
Assuming you already created $nic - network interface earlier
PS C:\azure> $vm = Add-azurermvmnetworkinterface -vm $vm -id $nic.id
PS C:\azure> new-azurermvm -resourcegroupname $rgname -location $location -vm $vm
Add the NW interface for the VM
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.id
Related
I have a Datacenter 2016 server with unmanaged disk. I need to be able to replicate this VM and continue using an unmanaged disk.
Do I need to provision the VM i want to replicate? Or can I just use the VHD in storage to create a new VM?
Here is my powershell script so far. Note that I tried to provision a VM
New-AzVm `
-ResourceGroupName "myResource" `
-Name "myVM" `
-ImageName "" ` //IS THIS WHERE YOU WOULD PUT A VHD?
-Location "West US 2" `
-VirtualNetworkName "my-vnet" `
-SubnetName "default" `
-SecurityGroupName "myvmNSG" `
-OpenPorts 3389, 80, 443
If you want to create an unmanaged VM from the VHD file, you can use the VM config. Here is an example using the existing NIC and VNet, you can also create the new one for it:
$NIC = Get-AzNetworkInterface -ResourceGroupName charlesUnmanaged -Name azurevm938
$VirtualMachine = New-AzVMConfig -VMName "azurevm" -VMSize "Standard_DS3"
$VirtualMachine = Add-AzVMNetworkInterface -VM $VirtualMachine -Id $NIC.Id
$VirtualMachine = Set-AzVMOSDisk -VM $VirtualMachine -Name "unmanagedos" -VhdUri $OSDiskUri -CreateOption Attach -Linux
New-AzVM -ResourceGroupName "charlesUnmanaged" -Location "East US" -VM $VirtualMachine -Verbose
I'm trying to swapout the OS disk on an Azure VM. The disk is a managed disk, the disk that I'm replacing it with is a managed disk. I follow the instructions that I have found in several documents for doing this in PS.
https://azure.microsoft.com/en-us/blog/os-disk-swap-managed-disks/
I get below message that leaves me to believe that it completed successfully.
RequestId IsSuccessStatusCode StatusCode ReasonPhrase
--------- ------------------- ---------- ------------
True OK OK
Here is the PS code that I am using:
$vm = Get-AzureRmVM -ResourceGroupName rgname -Name vmname
Stop-AzureRmVM -ResourceGroupName rgname -Name $vm.Name -Force
$disk = Get-AzureRmDisk -ResourceGroupName rgname -Name newosdiskname
Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $disk.Id -Name $disk.Name
Update-AzureRmVM -ResourceGroupName rgname -VM $vm
So why is this not working?
As the description in the document, you can replace the OS disk of an existing VM with a managed OS disk. So the replacement disk must be an OS disk, and you also cannot swatch the OS type, for example, from Linux to Windows.
And the PowerShell code that you use works fine on my side and the screenshot of the result shows like this:
And I think this function is used to replace the backup OS disk. So it's better to use a backup managed disk of the OS disk to replace.
Couldnot get this to work using PS. I was able to easily do it via CLI.
I have an Azure Image, which when I use Azure Powershell to create a VM from, despite me setting the ComputerName in the script, the VM is created without setting the ComputerName to the provided value.
Script:
$ImageName = 'MyImage'
$RsgName = 'MyRsg'
$VmName = 'MyNewVM'
$DiagnosticStorageName = 'diagnosticsstore5048'
$cred = Get-Credential -Credential 'TheAdmin'
$Image = Get-AzureRmImage -ImageName $ImageName -ResourceGroupName $RsgName
# Get NIC
$nic = Get-AzureRmNetworkInterface -ResourceGroupName $RsgName
# Configure the new VM
$Vm = New-AzureRmVMConfig -VMName $VmName -VMSize 'Standard_A2_v2'
$Vm = Set-AzureRmVMSourceImage -VM $Vm -Id $Image.Id
$Vm = Set-AzureRmVMOSDisk -VM $Vm -Name $VmName'-disk' -StorageAccountType 'StandardLRS' -DiskSizeInGB '128' -CreateOption FromImage -Caching ReadWrite
$Vm = Add-AzureRmVMNetworkInterface -VM $Vm -Id $nic.Id
$Vm = Set-AzureRmVMBootDiagnostics -VM $Vm -Enable -ResourceGroupName $RsgName -StorageAccountName $DiagnosticStorageName
$Vm = Set-AzureRmVMOperatingSystem -VM $Vm -Windows -ComputerName 'dor' -Credential $Cred -ProvisionVMAgent
New-AzureRmVM -VM $Vm -ResourceGroupName $RsgName -Location 'West Europe' -DisableBginfoExtension
Last time I run the script to create the VM, it left the new VM with a computer name of 'WIN-I80O6J22ENS'
The Image was created as per the process here: https://learn.microsoft.com/en-gb/azure/virtual-machines/windows/capture-image-resource?toc=%2Fazure%2Fvirtual-machines%2Fwindows%2Fclassic%2Ftoc.json
UPDATE
Alot of people think that I am not Generalizing the image correctly, so I wanted to add here how I am doing it.
Inside the VM I run:
Start-Process -FilePath $env:windir\System32\Sysprep\Sysprep.exe -ArgumentList "/generalize /oobe /shutdown /unattend:$env:windir\System32\Sysprep\unattend.xml"
Unattend.xml only has one setting in it which is to step the TimeZone.
Once this is completed and the VM OS has shut down, I run the following to get the VM, stop it, and set it to Generalized:
# Shutdown Source VM & Generalize
$SourceVM = Get-AzureRmVM -ResourceGroupName $SourceRsg -Name $SourceVMName
$Null = Stop-AzureRMVM -ResourceGroupName $SourceRsg -Name $SourceVMName -Force
Write-Host 'Stopped Source VM'
Set-AzureRmVm -ResourceGroupName $SourceRsg -Name $SourceVMName -Generalized
Write-Host 'Set Source VM to Generalized'
I have noticed that when the last command is ran, the output is:
OperationId :
Status :
StartTime :
EndTime :
Error :
It doesn't actually say if it was successful or not?
After this I create the Image from the VM disk.
It might be caused by the image not being "Generalized".
Take a look at the Create a managed image of a generalized VM in Azure guide.
Hope it helps!
If you have a specialized image, the Computer name will be missing because the old computer name and the new computer name share the same RID and SID number and on a ideal situation each virtual machine deployment has different RID and SID number. The Computer name can be displayed if the image is a generalized.
Check this article for more information:
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/create-vm-specialized
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/capture-image-resource
The point everyone is trying to make, from your description of the issue, it seems the Image was not generalized correctly or aspect of the generalization failed.
The script work fine on my end, so the only issue is with the image. Screenshot
Try another deployment from that image an see is you get the same computer name (WIN-I80O6J22ENS).
If you get the same name that is a sure confirmation of issue with generalization.
If the name changes it might mean that the machine you imaged has a policy that is not accepting the name 'dor' so the system is generating default name.
Either way issue is not with the Powershell or Azure. Hope this helps.
Is it true, that even for Virtual Machine's created in the latest platform (ARM), that if you initially created the machine with 1 NIC, that there is no way to add additional NICs to the VM?
I found a few random (non-Microsoft) articles that seem to indicate this is the case, which if so... is kind of retarded.
So I wanted to make sure that I'm understanding this correctly.
If I have to start all over and build a new machine just to add a NIC, I might consider just using Amazon AWS as I can't imagine this being a limitation over there.
that if you initially created the machine with 1 NIC, that there is no
way to add additional NICs to the VM
It is true, there is no way to add a NIC to an existing VM, and we can't via portal to create a VM with multiple NICs. But we can create/recreate the VM via powershell and add another NIC to it. Here is the powershell script:
$rg = "jason-newgroup"
$loc = "japan east"
$nic01 = "nic01"
$nic02 = "nic02"
$vnet = Get-AzureRmVirtualNetwork -Name ‘jason-newgroup-vnet’ -ResourceGroupName ‘jason-newgroup’
$sub01id = (Get-AzureRmVirtualNetworkSubnetConfig -Name ‘sub01’ -VirtualNetwork $vnet).Id
$sub02id = (Get-AzureRmVirtualNetworkSubnetConfig -Name ‘sub02’ -VirtualNetwork $vnet).Id
$ip1 = '10.1.0.5'
$ip2 = '10.1.1.5'
$nic1 = New-AzureRmNetworkInterface -Name $nic01 -ResourceGroupName $rg -Location $loc -SubnetId $sub01id -PrivateIpAddress $ip1
$nic2 = New-AzureRmNetworkInterface -Name $nic02 -ResourceGroupName $rg -Location $loc -SubnetId $sub02id -PrivateIpAddress $ip2
$vmsize = "Standard_DS4_v2"
$vmname = "jason-windows"
$vm = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize
$VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $nic1.Id -Primary
$VM = Add-AzureRmVMNetworkInterface -VM $VM -Id $nic2.Id
$osDiskName = "jason-newtest"
$osDiskVhdUri = "https://jasonnewgroupdisks717.blob.core.windows.net/vhds/jason-windows2016920165635.vhd"
$vm = Set-AzureRmVMOSDisk -VM $vm -VhdUri $osDiskVhdUri -name $osDiskName -CreateOption attach -windows
New-AzureRmVM -ResourceGroupName $rg -Location $loc -VM $vm
Notice:
The VM size determines the number of NICS that you can create for a VM. More information about how many NICS each VM size supports, please refer to the link below:
https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-sizes/
There is an update to this. You can now add nics to existing Azure VMs. See the documentation here for tutorial - https://learn.microsoft.com/en-us/azure/virtual-network/virtual-network-network-interface-vm
I am trying to add the WinRs support using the publically available ARM Template
I get the following error
Changing property 'windowsConfiguration.winRM.listeners' is not allowed
Then I tried using the powershell script mentioned in this article at the end. I'm not sure if it's just me who found the script to be a little wrong, cos it wasn't sorking so I changed it to as below
$vm = Get-AzureRmVM -ResourceGroupName "dscwitharm" -Name "dscwitharm"
$credential = Get-Credential
$secretURL = (Get-AzureKeyVaultSecret -VaultName "nithishvault" -Name "dscwitharmwinrs").Id
$vm = Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName "dscwitharm" -Credential $credential -WinRMHttps -WinRMCertificateUrl $secretURL
$sourceVaultId = (Get-AzureRmKeyVault -ResourceGroupName "dscwitharm" -VaultName "nithishvault").ResourceId
$CertificateStore = "My"
$vm = Add-AzureRmVMSecret -VM $vm -SourceVaultId $sourceVaultId -CertificateStore $CertificateStore -CertificateUrl $secretURL
Update-AzureRmVM -ResourceGroupName "dscwitharm" -VM $vm
And I still get the same error. What am I missing?
> Changing property 'windowsConfiguration.winRM.listeners' is not allowed
This seems to be a known issue and I found a work around. The following template uses a customScript extension to execute PowerShell to create a self signed certificate and configure WinRm over HTTPS.
https://github.com/Azure/azure-quickstart-templates/tree/master/201-vm-winrm-windows
This is indeed a different approach from what the documentation article recommends ARM Tempate