Error creating plan while provisioning Ubuntu DSVM using PowerShell - powershell

I'm trying to create an Ubuntu DSVM using PowerShell. I've determined that the Ubuntu DSVM image is released by publisher microsoft-ads, under offer linux-data-science-vm-ubuntu and SKU linuxdsvmubuntu. I gather that when specifying my VM config in PowerShell, I need to use Set-AzureRmVMPlan and Set-AzureRmVMSourceImage, and have tried the following:
$vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize Standard_D4s_v3
$vmConfig = Set-AzureRmVMPlan -VM $vmConfig -Name "linuxdsvmubuntu" -Product "linux-data-science-vm-ubuntu" -Publisher "microsoft-ads"
$vmConfig = Set-AzureRmVMOperatingSystem -VM $vmConfig -Linux -ComputerName $vmName -Credential $cred
$vmConfig = Set-AzureRmVMSourceImage -VM $vmConfig -PublisherName "microsoft-ads" -Offer "linux-data-science-vm-ubuntu" -Skus "linuxdsvmubuntu" -Version latest
$vmConfig = Add-AzureRmVMNetworkInterface -VM $vmConfig -Id $nic.Id
New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vmConfig
Unfortunately, I get an error message from the New-AzureRmVM command:
New-AzureRmVM : This resource was created without a plan. A new plan cannot be associated with an update.
ErrorCode: CannotSetPlanOnUpdate
ErrorMessage: This resource was created without a plan. A new plan cannot be associated with an update.
StatusCode: 400
ReasonPhrase: Bad Request
OperationID : 648c62cd-4029-408e-8b6c-2ae4310001f6
At line:1 char:1
+ New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vmC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureRmVM], ComputeCloudException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand
It seems that I might not be using Set-AzureRmVMPlan correctly. Is it clear to anyone what I'm doing wrong?

I discovered that the problem was not with this command itself, but apparently with a failed deployment from an earlier version of the command.
The first time I tried to use Set-AzureRmVMSourceImage, I was not aware that I needed to use Set-AzureRmVMPlan as well. This resulted in a failed deployment, which I assumed meant that the deployed VM would be deleted from my resource group (or never be added to my resource group in the first place).
What actually happened is that the failed deployment left a VM with status "Failed" in my resource group. When I later ran the commands shown above, the New-AzureRmVM command was treated as an update step instead of a brand new VM creation. That's why the error message indicates that, "This resource was created without a plan."
Deleting everything and starting over resulted in success with the commands above.

Related

Create a Disk in Azure New Portal is not working , old portal I could do it easily

I'm not even sure why azure even has a GUI Website. It is starting to feel a bit ridiculous when the old manage.windowsazure.com I could powershell up a VHD, and then very easily use a Storage and container and Add the image and then choose from gallery of my own images.
NOW I read that in May 2017 a lot of things with the old portal are going away. I created a Storage Account myvmblobs and then a container mywincontainer and then I uploaded a VHD , tmppro2.vhd is sitting there as a VHD Blob
URL https://myvmblobs.blob.core.windows.net/mywincontainer/TMPPRO2.VHD
So I read that I could create a Disk image from powershell ( I have to no way to do it with website portal.azure.com )
Add-AzureDisk 'tmppro2' -MediaLocation https://myvmblobs.blob.core.windows.net/mywincontainer/TMPPRO2.VHD -Label 'OS' -OS "Windows"
However, I don't know if the Label or OS is important...
Add-AzureDisk : BadRequest: The storage account with the name myvmblobs as specified in the VHD URI https://myvmblobs.blob.core.windows.net/mywincontainer/TMPPRO2.VHD does not exists in the current subscription
According to your description, we can use PowerShell or template to create new VM in Azure ARM module.
About PowerShell, here is a example script(use existing VHD):
$rgname = "jason-newgroup"
$loc = "japaneast"
$vmsize = "Standard_DS1_v2"
$vmname = "jason-newtest2"
$vm = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize
$nic = Get-AzureRmNetworkInterface -Name ("jason-newtest45") -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 -Linux
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $vm
Use template to create Azure VM:
Here is the template.
Update:
We can use azure storage explorer to upload VHD to Azure:

Assign Network Security Group to a Virtual Machine Network Interface using PowerShell

I have existing NSG and VM and planning to add the NSG to existing VM's NIC and simultaneously remove as well. I have prepared this based on example provided in http://windowsitpro.com/azure/manage-network-security-groups-powershel. The below command failing with method not supported errors.
$NICName = 'azwebvm0186'
$RGName = 'Prod_ResourceGroup'
$NsgName = 'Prod_ILB_SG'
$NSG = Get-AzureRmNetworkSecurityGroup -Name $NsgName -ResourceGroupName $RGName
$NIC = Get-AzureRmNetworkInterface -Name $NICName -ResourceGroupName $RGname
$NIC.NetworkSecurityGroup = $NSG
Set-AzureRmNetworkInterface -NetworkInterface $NIC
its failing with below error
$NIC.NetworkSecurityGroup = $NSG : Specified method is not supported.
+ CategoryInfo : NotImplemented: (:) [], PSNotSupportedException
+ FullyQualifiedErrorId : NotSupported
I have tested in my lab, your script works for me. I think you had better check as the following ways:
1.Check $NSG and $NIC.NetworkSecurityGroup value and type. Please ensure they have the same type.
PS C:\Users\v-shshui> $NIC|gm
TypeName: Microsoft.Azure.Commands.Network.Models.PSNetworkInterface
2. Check your Azure Powershell version. My version is 3.3.0. You could get version by use the following cmdlet.
Get-Module -ListAvailable -Name Azure -Refresh
If your version is not latest, I suggest you could update your version to latest. You can download the PS version 3.3.0 installation file from this link

Azure Microsoft.Azure.Diagnostics Extension

Trying to configure the BootDiagnostics on a VM on a storage account in a resource group different from the VMs. To the best of my knowledge this can only be done by installing the VmDiagnosticsExtension. I'm executing the following:
Set-AzureRmVMDiagnosticsExtension -ResourceGroupName $RgName -VMName $VmName `
-DiagnosticsConfigurationPath 'D:\DiagnosticsConfig.xml' `
-StorageAccountEndpoint '/subscriptions/ff26f7/resourceGroups/rgroup/providers/Microsoft.Storage/storageAccounts/amsdiag01'`
-StorageAccountName 'amsdiag01' `
-StorageAccountKey 'key''>
I get this error message:
ErrorMessage: Handler 'Microsoft.Azure.Diagnostics.IaaSDiagnostics'
has reported failure for VM Extension
'Microsoft.Insights.VMDiagnosticsSettings' with terminal error code
'1009' and error message: 'Enable failed for plugin (name:
Microsoft.Azure.Diagnostics.IaaSDiagnostics, version 1.6.3.0) with
exception Command
C:\Packages\Plugins\Microsoft.Azure.Diagnostics.IaaSDiagnostics\1.6.3.0\DiagnosticsPluginLauncher.exe
of Microsoft.Azure.Diagnostics.IaaSDiagnostics has exited with Exit
code: -106'
No further information available in C:\WindowsAzure\Logs\WaAppAgent.log on server. In the portal under 'Diagnostics' I can see the correct configuration. But the extension is in a '(unavailable)' state. Container in storage account is not created. Also, can't reboot the server due to the extension. I can remove and re-add the extension using PowerShell, but always same result. When performing a Get-AzureRmVMExtension I see the following 'Public Settings' entry:
PublicSettings : {
"storageAccount": "amsdiag01",
"xmlCfg": "PFdhZENmZz4NCiAgICAgIDxEaWFnbm9zdGljTW9uaXRvckNvbmZpZ3VyYXRpb24gb3ZlcmFsbFF1b3RhSW5NQj0iNDA5NiI+DQogICAgICAgIDxQZXJmb3JtYW5jZUNvdW50ZXJzIHNjaGVkdWxlZFRyYW5zZmVyUGVyaW9kPSJQVDFNIj4NCsKgwqDCoMKgwqAgICAgIDxQZXJmb3JtYW5jZUNvdW50ZXJDb25maWd1cmF0aW9uIGNvdW> eU5hbWU9IkNQVSBwcml2aWxlZ2VkIHRpbWUiIGxvY2FsZT0i
I've chosen not to use extensions but instead using the following:
$RgName = 'RG1'
$VmName = 'VM01'
$Vm = Get-AzureRmVM -ResourceGroupName $RgName -Name $VmName
$Vm = Set-AzureRmVMBootDiagnostics -Enable -VM $Vm -ResourceGroupName $RgName -StorageAccountName diagss01
Update-AzureRmVM -ResourceGroupName $RgName -VM $Vm

getting error when creating VM in Azure RM using an existing image using powershell

I am creating a new VM using Azure RM from a copied image; the error is:
New-AzureRMVM : Source and destination storage accounts for disk osdisk are different.
StatusCode: 409
ReasonPhrase: Conflict
OperationID : 'c55f44a7-b46c-423c-aa52-6bb8a99391ee'
New-AzureRMVM -ResourceGroupName $resourceGroupName -Location $location -VM $vm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : CloseError: (:) [New-AzureRmVM], ComputeCloudException
FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand
what am I missing?
Its in the error message, it not posible to deploy a vhd from a diffrent storage account when creating a VM.
You will have to copy the VHD over to the same storage account the VM will run out of before you start to deploy the VHD.
Copy past from here: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-upload-image/
Note: The VM needs to be in the same storage account as the uploaded
VHD file.
To fix it, you can do something along these lines before you deploy the first VM:
$SourceContext = (Get-AzureRmStorageAccount -ResourceGroupName $VhdSourceResouceGroup -StorageAccountName $VhdSourceStorageAccount).Context
$DestinationContext = (Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -StorageAccountName $VhdStorageAccount).Context
New-AzureStorageContainer -Name "source" -Context $DestinationContext -ErrorAction Ignore
Start-AzureStorageBlobCopy `
-SrcUri "$($SourceContext.BlobEndPoint)source/$Image" `
-SrcContext $SourceContext `
-DestContainer "source" `
-DestBlob $Image -ConcurrentTaskCount 24 `
-DestContext $DestinationContext | Get-AzureStorageBlobCopyState -WaitForComplete

Creating a VM in Azure using Powershell

I am trying to create a VM in Azure using powershell. I am running this on my local PC. I have been able to setup websites and SQL Azure instances without any issues but None of the samples on the web work.
Import-Module Azure
Import-AzurePublishSettingsFile -PublishSettingsFile "C:\Cloud\Azure.publishsettings"
$VMImage = #(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 R2 Datacenter, November 2014").ImageName
$myVMName = "jsTestVM1"
$myAdminName ="jsTestAdmin1"
$myAdminPwd ="not telling you"
New-AzureQuickVM -ImageName $VMImage -Windows -Name $myVMName -ServiceName $myVMName -AdminUsername $myAdminName -Password $myAdminPwd -InstanceSize "ExtraSmall"
I get the following message:
New-AzureQuickVM : ResourceNotFound: The hosted service does not exist.
At line:1 char:1
+ New-AzureQuickVM -ImageName $VMImage -Windows -Name $myVMName -ServiceName $myVM ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [New-AzureQuickVM], CloudException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.ServiceManagement.IaaS.PersistentVMs.NewQuickVM
I've tried samples from the web and they give the same error message as well.
Edit:
If I specify a location I get the error message 'Service already exists, Location cannot be specified'.
If I specify AffinityGroup I get 'Service already exists, AffinityGroup cannot be specified'
$VMImage = #(Get-AzureVMImage | Where-Object -Property Label -Match "Windows Server 2012 R2 Datacenter, November 2014").ImageName
$myVMName = "srikstest"
$myAdminName ="srikstest"
$myAdminPwd ="NeitherMe"
New-AzureQuickVM -Windows -ServiceName $myVMName -ImageName $VMImage -AdminUsername $myAdminName - Password $myAdminPwd -InstanceSize "ExtraSmall" -Location "Southeast Asia" -Name $myVMName -Verbose
You can create a new Azure service for the virtual machine by specifying either the Location or AffinityGroup parameters, or deploy the new virtual machine into an existing service.
I've just added the location parameter and it worked !!
In the end I added an affinity group and changed the service name I was using. This enabled me to create the VM. The service name I was using was not in use as far as I was aware in my subscription so either a previous failed install left some artefact around or the name needs to be globally unique. I've checked the docs here
http://msdn.microsoft.com/en-us/library/azure/dn495183.aspx
and it doesn't state the service name needs to be globally unique
Assign/replace the value to variable.
New-AzureVMConfig -Name $VmName -InstanceSize $InstanceSize -Label $VmName -ImageName $Imagename -DiskLabel $DiskLabel |
add-azureprovisioningconfig -LinuxUser $cred.GetNetworkCredential().Username -Linux -Password $cred.GetNetworkCredential().Password -SSHPublicKeys $sshkey |
Add-AzureEndpoint -LocalPort $LocalPort1 -Name $LocalPortName1 -Protocol tcp -PublicPort $LocalPort1 |
New-AzureVM -ServiceName $CloudServiceName -AffinityGroup $AffinityGroup –WaitForBoot