Set-AzureRmVMOperatingSystem returns error on New-AzureRmVm
I try to create a VM based on an existing VHD, I get an error when I run New-AzureRmVm if Set-AzureRmVMOperatingSystem was used.
Consider the following script:
$ad02 = New-AzureRmVMConfig -VMName AD-02 -VMSize Standard_A1
$ad02 | Set-AzureRmVMOSDisk -VhdUri https://xxx.blob.core.windows.net/vhds/AD-02.vhd -Name AD-02 -CreateOption attach -Windows -Caching ReadWrite
$ad02 | Add-AzureRMVMDataDisk -Name AD-02-Data -VhdUri https://xxx.blob.core.windows.net/vhds/AD-02-Data.vhd -LUN 0 -Caching ReadWrite -CreateOption Attach -DiskSizeInGB 10
$ad02ip = Get-AzureRmPublicIpAddress -Name AD-02 -ResourceGroupName group
$ad02sn = Get-AzureRmVirtualNetwork -ResourceGroupName Production -Name subnet
$ad02nic = Get-AzureRmNetworkInterface -Name AD-02912 -ResourceGroupName group
Add-AzureRmVMNetworkInterface -Id $ad02nic.Id -VM $ad02
$user = "xxx";
$password = 'secret';
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
$ad02 = Set-AzureRmVMOperatingSystem -VM $ad02 -Windows -ComputerName AD-02 -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
New-AzureRMVM -ResourceGroupName group -Location “West Europe” -VM $ad02 -Verbose
When I run the script, I get the following error
New-AzureRMVM : InvalidParameter: Parameter 'osProfile' is not allowed. OperationID : '40b68b6e-b9ab-4508-8326-7c3e79b2a6e7' At C:\Users\xxx\Desktop\Add VM.ps1:24 char:1
- New-AzureRMVM -ResourceGroupName group -Location “West Europe” - ...
- CategoryInfo : CloseError: (:) [New-AzureRmVM], ComputeCloudException - FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand
Any idea ?
Thanks :)
@JohannBlais Is the existing VHD generalized or specialized ?
It is a VHD copied from another subscription, the other VM was deallocated when the files were copied.
@JohannBlais Was sysprep ever run on the VM before copying the VHD?
Sorry for the delayed answer, no it was not. The VM was created, shut down, the disks transfered, then the script was run to recreate the VM on the other subscription.
@JohannBlais In that case try adapting this script for your scenario
# Variables
## Global
$rgName = "testrg"
$location = "westus"
## Storage
$storageName = "teststore"
$storageType = "Standard_GRS"
## Network
$nicname = "testnic"
$subnet1Name = "subnet1"
$vnetName = "testnet"
$vnetAddressPrefix = "10.0.0.0/16"
$vnetSubnetAddressPrefix = "10.0.0.0/24"
## Compute
$vmName = "testvm"
$computerName = "testcomputer"
$vmSize = "Standard_A2"
$osDiskName = $vmName + "osDisk"
# Resource Group
New-AzureRmResourceGroup -Name $rgName -Location $location
# Storage
$storageacc = New-AzureRmStorageAccount -ResourceGroupName $rgName -Name $storageName -Type $storageType -Location $location
# Network
$pip = New-AzureRmPublicIpAddress -Name $nicname -ResourceGroupName $rgName -Location $location -AllocationMethod Dynamic
$subnetconfig = New-AzureRmVirtualNetworkSubnetConfig -Name $subnet1Name -AddressPrefix $vnetSubnetAddressPrefix
$vnet = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $rgName -Location $location -AddressPrefix $vnetAddressPrefix -Subnet $subnetconfig
$nic = New-AzureRmNetworkInterface -Name $nicname -ResourceGroupName $rgName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id
# Compute
## Setup local VM object
$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$osDiskUri = "https://test.blob.core.windows.net/vhds/osdiskforlinuxsimple.vhd"
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption attach -Linux
## Create the VM in Azure
New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm -Verbose -Debug
you need to remove the Set-AzureRMVMOperatingSystem command when attaching.
remove this line...
$ad02 = Set-AzureRmVMOperatingSystem -VM $ad02 -Windows -ComputerName AD-02 -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
I got quite in the same scenario, my colleague has generalised the VHD. I am looking into creating a VM using the VHD and landed with the same error. Can you guys help me out on this one?
I have taken a copy of VHD using Azure Blob copy (Powershell) and the VM the VHD was primarily attached to is not booting either.
$vNet = Get-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $RGVnet $SubnetIndex = '8'
$pip = New-AzureRmPublicIpAddress -Name $nicName -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic $nic = New-AzureRmNetworkInterface -Name $nicName -ResourceGroupName $rgName -Location $locName -SubnetId $vnet.Subnets[$subnetIndex].Id -PublicIpAddressId $pip.Id #Get-AzureRmVMSize -Location $locName | Select Name $vm= New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize $cred=Get-Credential -Message "Type the name and password of the local administrator account." $vm=Set-AzureRmVMOperatingSystem -VM $vm -Windows -ComputerName $vmName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate #$vm=Set-AzureRmVMSourceImage -VM $vm -PublisherName $pubName -Offer $offerName -Skus $skuName -Version "latest" $vm=Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$diskName="Windows"
#$storageAcc=Get-AzureRmStorageAccount -ResourceGroupName $rgName -Name $saName
$osDiskUri= "
Set-AzureRmVMOSDisk
New-AzureRmVM -ResourceGroupName $rgName -Location $locName -VM $vm
@arunshouri See comment https://github.com/Azure/azure-powershell/issues/1597#issuecomment-181910787
Hi,
I have created generalised VHD and trying to create a VM using the Java-SDK. Please find the code below,
**************************** Java code that I have written is as below,
if(platform.equalsIgnoreCase("linux")||platform.equalsIgnoreCase("unix")) { vm = azure.virtualMachines().define(vmName).withRegion(region).withExistingResourceGroup(rgName) .withNewPrimaryNetwork(primaryNetwork).withPrimaryPrivateIpAddressDynamic() .withNewPrimaryPublicIpAddress(dnsName).withOsDisk(VHDUrl, OperatingSystemTypes.LINUX) .withSize(VirtualMachineSizeTypes.STANDARD_DS1_V2).create(); }else if(platform.equalsIgnoreCase("windows")) { vm = azure.virtualMachines().define(vmName).withRegion(region).withExistingResourceGroup(rgName) .withNewPrimaryNetwork(primaryNetwork).withPrimaryPrivateIpAddressDynamic() .withNewPrimaryPublicIpAddress(dnsName).withOsDisk(VHDUrl, OperatingSystemTypes.WINDOWS) .withSize(VirtualMachineSizeTypes.STANDARD_DS1_V2).create(); }else{ Log.Message("Invalid platform provided.", LogLevel.ERROR); return null; }
************************************* While running the code I am getting below error,
com.microsoft.azure.CloudException: Parameter 'osProfile' is not allowed.: Parameter 'osProfile' is not allowed. at com.microsoft.azure.AzureClient.createExceptionFromResponse(AzureClient.java:521) at com.microsoft.azure.AzureClient.access$000(AzureClient.java:34) at com.microsoft.azure.AzureClient$1.call(AzureClient.java:133) at com.microsoft.azure.AzureClient$1.call(AzureClient.java:130) at rx.internal.operators.OnSubscribeMap$MapSubscriber.onNext(OnSubscribeMap.java:69) at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$RequestArbiter.request(RxJavaCallAdapterFactory.java:173) at rx.Subscriber.setProducer(Subscriber.java:211) at rx.internal.operators.OnSubscribeMap$MapSubscriber.setProducer(OnSubscribeMap.java:102) at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:152) at retrofit2.adapter.rxjava.RxJavaCallAdapterFactory$CallOnSubscribe.call(RxJavaCallAdapterFactory.java:138)
Please help me to resolve the error. I need to create multiple VM's using that image.
i got stuck with the same issue and therefore I am here. Just looked up at the solution and can see we need to remove the following command : Set-AzureRmVMOperatingSystem. Microsoft says the same (https://docs.microsoft.com/en-us/powershell/module/azurerm.compute/set-azurermvmoperatingsystem?view=azurermps-4.1.0)
they say that this piece of command is only for new VM creation.
Iam also facing same issue.I syscripted an ubuntu vhd , upload it to my storage account and run the following script to create image out of it.But got the above error(osProfile missing).Any solution
Select-AzureRmSubscription -SubscriptionName "AILDGPL008"
Global Variables
$ResourceGroupName = "arun999" $location = "South India"
Network
$nicname = "arun111" $subnetName = "arunsubnet" $vnetName = "arunvnet" $vnetAddressPrefix = "10.0.0.0/16" $vnetSubnetAddressPrefix = "10.0.0.0/24" $publicIPName = "mypubip"
Compute
$vmName = "arun123vm" $computerName = "testimage" $vmSize = "Standard_A0" $osDiskName = $vmName + "osDisk"
#The password must be at 12-123 characters long and have at least one lower case character, one upper case character, one number, and one special character. $adminUsername = 'labadmin' $adminPassword = 'P@ssw0rd@123'
#Create New Os Disk uri $osDiskUri = "https://testingstorage19.blob.core.windows.net/myblob/ubuntunew.vhd"
#Image URI you can Find Storage group --> Blob --> System -->Microsoft.Compute -->Images --> your conntainer Name --> vhd name given while caputure VM. $imageUri = "https://testingstorage19.blob.core.windows.net/myblob/ubuntu%20-%202.vhd"
#Create New Resouce Group New-AzureRmResourceGroup -Name $ResourceGroupName -Location $location
#Create a virtual network $singleSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix $vnetSubnetAddressPrefix $vnet = New-AzureRmVirtualNetwork -Name $vnetName -ResourceGroupName $ResourceGroupName -Location $location -AddressPrefix $vnetAddressPrefix -Subnet $singleSubnet
#Create a public IP address and network interface $pip = New-AzureRmPublicIpAddress -Name $publicIPName -ResourceGroupName $ResourceGroupName -Location $location -AllocationMethod Dynamic $nic = New-AzureRmNetworkInterface -Name $nicname -ResourceGroupName $ResourceGroupName -Location $location -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id
#Create a virtual machine
#The password must be at 12-123 characters long and have at least one lower case character, one upper case character, one number, and one special character.
$cred = New-Object PSCredential $adminUsername, ($adminPassword | ConvertTo-SecureString -AsPlainText -Force)
$vm = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize
$vm = Set-AzureRmVMOperatingSystem -VM $vm -Linux -ComputerName $computerName -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri -CreateOption FromImage -SourceImageUri $imageUri ` -Caching ReadWrite -Linux
#running below command you can see your VM attached parameters. $VM = Set-AzureRmVMBootDiagnostics -VM $vm -Disable
#Create the new VM New-AzureRmVM -ResourceGroupName $ResourceGroupName -Location $location -VM $vm
Same issue. GEneralized VHD. Set-AzureRMVMOsDisk runs, then I have to comment out the Set-AzureRMVMOperatingSystem part... ... but then how can I specify Username, Password, and WINRM and ProvisionVMAgent ???
Encounter same issue when trying to use generalized vhd from a custom osdirkuri, along when setting with OperationSystem to set the login credential. Anyway, to work around this limitation?
How was this issue closed? I get the same behavior and error: "Parameter 'osProfile' is not allowed." Commenting out the Set-AzureRMVMOperatingSystem is not a solution, since you need it to specify the credentials and computername.
i got stuck with the same issue and therefore I am here. Just looked up at the solution and can see we need to remove the following command : Set-AzureRmVMOperatingSystem. Microsoft says the same (https://docs.microsoft.com/en-us/powershell/module/azurerm.compute/set-azurermvmoperatingsystem?view=azurermps-4.1.0)
they say that this piece of command is only for new VM creation.
Sorry to revive this old thread, but as I am having this issue, here we go. I am in fact creating a new VM, I'm using an existing specialized VHD which I imported, but we are creating a new VM.
Same Problem here. We want to create the Disc Object before we create the VM itself, so we have better Control over the Disc Tags. The Disc is created From Image und afterwards attached to the VM. Everything works as expected, but we cannot issue "Set-AzureRMVMOperatingSystem" and therefore cannot set the VM-Admin Credentials nor everything else what this Cmdlet does.
Same issue here, but we are trying it with ARM templates. If we define OS disk upfront using ARM with "createOption": "FromImage", then we see issues when defining VM, where osDIsk is using "createOption": "Attach" and "osProfile" is not allowed parameter. Then we cannot define admin user and so on.
To follow up on my previous post, I went through my code repeatedly & could find nothing wrong, yet this continued to fail. I finally stepped through it one command & a time & it worked perfectly....so I tried another VM with a different disk, & it performed exactly the same. YMMV, but it might be worth a shot.
Same issue if I remove Set-AzureRMVMOperatingSystem it creates the new VM but I can't even login with credentials of original VM (from which I created the VHD)!! I have to go to UI and reset the password...