Azure Microsoft.Azure.Diagnostics Extension - powershell

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

Related

Creating OS disk from VHD stored in another storage account

Have an existing PowerShell script that is creating VM's using pre-created VHD's stored in a storage account (copied across regional storage accounts for speed).
In PS we can use the following:
New-AzureRmDisk -DiskName $osDiskName -Disk `
(New-AzureRmDiskConfig -AccountType Premium_LRS `
-Location $location -CreateOption Import `
-StorageAccountId $storageAccountId `
-SourceUri $osVHDUri) `
-ResourceGroupName $resourceGroupName
$osDisk = Get-AzureRMDisk -DiskName $osDiskName -ResourceGroupName $resourceGroupName
$VirtualMachine = Set-AzureRmVMOSDisk -VM $VirtualMachine -ManagedDiskId $osDisk.Id -CreateOption Attach -Windows -StorageAccountType Premium_LRS
Where $storageAccountId is similar to:
/subscriptions/{0}/resourceGroups/my-snapshot/providers/Microsoft.Storage/storageAccounts/mysnapshots -f $sourceSnapshotSubscriptionId
In the .net Azure SDK, I don't see a way to replicate this? When I try to create, it's saying unable to find, yet my PS works ok.
If you want to use an existing disk instead of a marketplace image, use this code:
var managedDisk = azure.Disks.Define("myosdisk")
.WithRegion(location)
.WithExistingResourceGroup(groupName)
.WithWindowsFromVhd("https://mystorage.blob.core.windows.net/vhds/myosdisk.vhd")
.WithSizeInGB(128)
.WithSku(DiskSkuTypes.PremiumLRS)
.Create();
azure.VirtualMachines.Define("myVM")
.WithRegion(location)
.WithExistingResourceGroup(groupName)
.WithExistingPrimaryNetworkInterface(networkInterface)
.WithSpecializedOSDisk(managedDisk, OperatingSystemTypes.Windows)
.WithExistingAvailabilitySet(availabilitySet)
.WithSize(VirtualMachineSizeTypes.StandardDS1)
.Create();
Check this link for further reference. Hope it helps.

Error creating plan while provisioning Ubuntu DSVM using 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.

Remove-AzureRmResourceGroupDeployment not removing the azure dev test lab

I created a dev test lab from powershell using the command :
New-AzureRmResourceGroupDeployment -Name MyLab -ResourceGroupName MyLabRG -TemplateUri https://raw.githubusercontent.com/azure/azure-quickstart-templates/master/101-dtl-create-lab/azuredeploy.json
Now after I am done doing some operations in the lab, I want to delete it. So I use
Remove-AzureRmResourceGroupDeployment -Name MyLab -ResourceGroupName MyLabRG
It returns True, but when I check the Dev Test lab in portal, it is still there. Am I missing something?
If you want to remove the dev test lab, please have a try to use the following command, it works correctly on my side.
Remove-AzureRmResource -ResourceGroupName $resourcegroupName -ResourceType Microsoft.DevTestLab/labs -ResourceName $resourceName -ApiVersion 2016-05-15 -Force

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:

AzureRM Automation PSWorkflow Runbook - error while attaching NIC to subnet

I'm trying to create a parallel Workflow script but facing some challenges while attaching NIC to existing Subnet. I'm getting the following error.
Microsoft.PowerShell.Utility\Write-Error : Cannot validate argument on
parameter 'SubnetId'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
Following is my Workflow script which creates VNet, Subnet, NSG, PIP and tries to create NIC from AzureRM automation Runbook.
"Get Virtual Network Information" $gvnet = Get-AzureRmVirtualNetwork
-Name $VNetName -ResourceGroupName $SharedResourcesRGName
$nic = New-AzureRmNetworkInterface -Name "$VMName-NIC"
-ResourceGroupName $VMName -Location $VMLocation `
        -SubnetId $gvnet.Subnets[0].ID -PublicIpAddressId $pip.Id -NetworkSecurityGroupId $gnsg.Id -Force
How do I get the value of Subnet in AzureRM Workflow runbook
Gulab Pasha