xt4k

Untitled

Oct 23rd, 2021
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #create-managed-disk-from-snapshot
  2. #Provide the name of your resource group
  3. $resourceGroupName ='APP-RG'
  4. #Provide the name of the snapshot that will be used to create Managed Disks
  5. $snapshotName = 'West_Europe_AppVer2021_10_0_21_2021-oct-19'
  6. $dt = Get-Date -Format "MM-dd-yyyy_HH-mm-ss"
  7. #Provide the name of the Managed Disk
  8. $diskName = 'RegressionAppSrvOsDisk_'+$dt
  9. #Provide the size of the disks in GB. It should be greater than the VHD file size.
  10. $diskSize = '128'
  11. #Provide the storage type for Managed Disk. PremiumLRS or StandardLRS.
  12. $storageType = 'Premium_LRS'
  13. #Get-AzLocation
  14. $location = 'westeurope'
  15. $snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName
  16. $diskConfig = New-AzDiskConfig -SkuName $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id -DiskSizeGB $diskSize
  17. New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName
  18. $disk = Get-AzDisk -ResourceGroupName $resourceGroupName -DiskName $diskName
  19. # swap-os-disk-of-an-azure-vm
  20. $vmName = 'Auto-Regression-App-Server'
  21. # Get the VM
  22. $vm = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
  23. # Make sure the VM is stopped\deallocated
  24. $stoppedVm =Stop-AzVM -ResourceGroupName $resourceGroupName -Name $vm.Name -Force
  25. # Get the new disk that you want to swap in
  26. $disk = Get-AzDisk -ResourceGroupName $resourceGroupName -Name $diskName
  27. # Set the VM configuration to point to the new disk
  28. $setNewDisk =Set-AzVMOSDisk -VM $vm -ManagedDiskId $disk.Id -Name $disk.Name
  29. # Update the VM with the new OS disk
  30. $updatedVm = Update-AzVM -ResourceGroupName $resourceGroupName -VM $vm
  31. # Start the VM
  32. $startedVm = Start-AzVM -Name $vm.Name -ResourceGroupName $resourceGroupName
Advertisement
Add Comment
Please, Sign In to add comment