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

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:

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.

how to copy capture images in azure from one subscription to another subscription

i am trying to copy azure captured image from one subscription-another subscription currently in portal move is coming soon so i am trying to copy it and searching for some power shell script i don't want to create a vm from that with out creating vm i am trying to copy
it is managed disk through power shell i can copy managed disk from one subscription-another by creating vm from it but i am trying without creating vm i am trying copy or move capture image is this possible with power shell can any have idea about this.?
i am trying copy or move capture image is this possible with power
shell can any have idea about this.?
No, it is not possible. Image does not copy from one subscription to another subscription. You need copy image's managed disk to other subscription.
You have two option.
1.Using image's managed to create a snapshot and copy this snapshot to other subscription, then using this snapshot to create a managed disk, then create a image.
#Create a snapshot from managed disk
$disk = "/subscriptions/************/resourceGroups/SHUICLI/providers/Microsoft.Compute/disks/shui_OsDisk_1_21af43450987448184b5e9793da08e54"
$snapshot = New-AzureRmSnapshotConfig -SourceUri $disk.Id -CreateOption Copy -Location $region
$snapshotName = $imageName + "-" + $region + "-snap"
New-AzureRmSnapshot -ResourceGroupName $resourceGroupName -Snapshot $snapshot -SnapshotName $snapshotName
#copy the snapshot to another subscription, same region
$snap = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName
#change to the target subscription
Select-AzureRmSubscription -SubscriptionId $targetSubscriptionId
$snapshotConfig = New-AzureRmSnapshotConfig -OsType Windows `
-Location $region `
-CreateOption Copy `
-SourceResourceId $snap.Id
$snap = New-AzureRmSnapshot -ResourceGroupName $resourceGroupName `
-SnapshotName $snapshotName `
-Snapshot $snapshotConfig
More information about this please refer to this blog.
2.Copy image's managed disk to a storage account, then using this VHD to create a new image.
##create $SAS
$sas = Grant-AzureRmDiskAccess -ResourceGroupName shui -DiskName shuitest -DurationInSecond 3600 -Access Read
$destContext = New-AzureStorageContext –StorageAccountName contosostorageav1 -StorageAccountKey 'YourStorageAccountKey'
Start-AzureStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer 'vhds' -DestContext $destContext -DestBlob 'MyDestinationBlobName.vhd'
See this answer.

Restore managed OS disk snapshot to existing VM

Similar to this one but powershell exclusively and with managed disks and an existing VM.
I took a snapshot of a managed OS disk and want to restore it but can't figure out how. I have tried a number of things but now think that you can't detach an OS disk even if the VM is deallocated. No matter how much I pore through the reference, I can't find anything to help me restore a snapshot to an existing disk. Is this even possible?
I can't find anything to help me restore a snapshot to an existing
disk. Is this even possible?
As far as I know, Azure does not support restore a snapshot to an existing disk.
But we can use the snapshot to create a Managed Disk and attach it to an existing VM.
Here is the PowerShell script use snapshot to create a Managed Disk:
PS C:\Users> $resourceGroupName = 'vm'
PS C:\Users> $snapshotResourceGroupName = 'vm'
PS C:\Users> $snapshotName = 'manageddisk1'
PS C:\Users> $managedDiskType = 'StandardLRS'
PS C:\Users> $location = 'eastus'
PS C:\Users> $managedDiskCreateOption = 'Copy'
PS C:\Users> $diskName = 'manageddisk2'
PS C:\Users> $snapshot = Get-AzureRmSnapshot -SnapshotName $snapshotName -ResourceGroupName $snapshotResourceGr
oupName
PS C:\Users> $diskConfig = New-AzureRmDiskConfig -AccountType $managedDiskType -Location $location -CreateOptio
n $managedDiskCreateOption -SourceResourceId $snapshot.Id
PS C:\Users> New-AzureRmDisk -DiskName $diskName -Disk $diskConfig -ResourceGroupName $resourceGroupName
AccountType : StandardLRS
TimeCreated : 4/21/2017 1:26:27 PM
OsType : Windows
CreationData : Microsoft.Azure.Management.Compute.Models.CreationData
DiskSizeGB : 128
EncryptionSettings :
OwnerId :
ProvisioningState : Succeeded
Id : /subscriptions/5384xxxx-xxxx-xxxx-xxxx-xxxxe29axxxx/resourceGroups/vm/providers/Microsoft.Compute/
disks/manageddisk2
Name : manageddisk2
Type : Microsoft.Compute/disks
Location : eastus
Tags :
If you want to attach it to an existing VM, we can use this script:
PS C:\Users> $datadisk2 = Get-AzureRmDisk -ResourceGroupName vm -DiskName manageddisk2
PS C:\Users> $vmName = 'jasonvm'
PS C:\Users> $rgname = 'vm'
PS C:\Users> $dataDiskName = 'manageddisk2'
PS C:\Users> $vm = Get-AzureRmVM -Name $vmName -ResourceGroupName $rgName
PS C:\Users> $vm = Add-AzureRmVMDataDisk -VM $vm -Name $dataDiskName -CreateOption Attach -ManagedDiskId $dataD
isk2.Id -Lun 2
PS C:\Users> Update-AzureRmVM -VM $vm -ResourceGroupName $rgName
RequestId IsSuccessStatusCode StatusCode ReasonPhrase
--------- ------------------- ---------- ------------
True OK OK
In this way, we can find this managed disk in Azure VM:
The New-AzureRMDiskConfig command has a switch -SourceResourceId that you can use to point to the snapshot you have created.
For example:
$diskConfig = New-AzureRMDiskConfig -CreateOption Copy -SourceResourceId <<id>> -Location westus -DiskSizeGB 64 -AccountType StandardLRS
The resource ID is that of your managed disk snapshot which can be found under the properties for that snapshot in the portal.
After that, you would create a new disk from this disk config. For example
$disk = New-AzureRmDisk -DiskName "name" -Disk $diskConfig -ResourceGroupName rgname
After you run that, you will see a new disk in the target resource group. You can then use that to create a VM or attach as required.
UPDATE: Official documentation can be found here. Please note
that in that example they use the -CreateOption Import rather than
Copy like I did.

Enabling disk encryption fails for Azure Ubuntu 16.04-LTS saying "'VolumeType' is not supported"

Azure Disk Encryption for Windows and Linux IaaS VMs says that "Linux OS disk encryption is currently supported on ... Ubuntu 16.04" however when I create a new VM
$vm = New-AzureRmVMConfig -VMName "vmname" -VMSize "Standard_D2_v2"
$vm = Set-AzureRmVMOperatingSystem -VM $vm -Linux -ComputerName "vmname" -Credential $cred
$vm = Set-AzureRmVMSourceImage -VM $vm -PublisherName "Canonical" -Offer "UbuntuServer" -Skus "16.04-LTS" -Version "latest"
$vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id
$osDiskUri = $storage_account.PrimaryEndpoints.Blob.ToString() + "vhds/vmname.vhd"
$vm = Set-AzureRmVMOSDisk -VM $vm -Name "myOsDisk1" -VhdUri $osDiskUri -CreateOption fromImage
New-AzureRmVM -ResourceGroupName "rgname" -Location "East US" -VM $vm
and then run
Set-AzureRmVMDiskEncryptionExtension -ResourceGroupName "rgname" -VMName "vmname" -AadClientID "appname" -AadClientSecret "xxx=" -DiskEncryptionKeyVaultUrl $KeyVault.VaultUri -DiskEncryptionKeyVaultId $KeyVault.ResourceId;
then I get this error:
Set-AzureRmVMDiskEncryptionExtension : Long running operation failed with status 'Failed'.
ErrorCode: VMExtensionProvisioningError
ErrorMessage: VM has reported a failure when processing extension 'AzureDiskEncryptionForLinux'. Error message: "VolumeType "" is not supported".
StartTime: 6/01/2017 3:12:44 PM
EndTime: 6/01/2017 3:14:49 PM
OperationID: b976c3ab-fe5b-4356-b62f-96f3b80aeba1
This post suggests there may be some way to apply encryption earlier than this, but actually I think it relates to people with already-encrypted drives they are trying to move into Azure.
What am I doing wrong? How can I use PowerShell to enable disk encryption on Ubuntu?
For now, Azure does not support use Set-AzureRmVMDiskEncryptionExtension to encrypt Linux OS disk. Please refer to this article
-VolumeType
Specifies the type of virtual machine volumes to perform the encryption operation. Allowed values for virtual machines that run the Windows operating system are as follows: All, OS, and Data.
The allowed values for Linux virtual machines are as follows: Data only.
You need prepare a pre-encrypted Linux VHD and use the VHD to create an encrypted Linux VM on Azure.
Please refer to the following steps.
1.Create an Ubuntu 16.0.4 VM on Azure.
2.Prepare a pre-encrypted Linux VHD. Please refer to this article.Notes: You need prepare the VHD on-premise.
3.Upload VHD to Azure.
4.Use template to create an encrypted Linux VM on Azure.

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