Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #create-managed-disk-from-snapshot
- #Provide the name of your resource group
- $resourceGroupName ='APP-RG'
- #Provide the name of the snapshot that will be used to create Managed Disks
- $snapshotName = 'West_Europe_AppVer2021_10_0_21_2021-oct-19'
- $dt = Get-Date -Format "MM-dd-yyyy_HH-mm-ss"
- #Provide the name of the Managed Disk
- $diskName = 'RegressionAppSrvOsDisk_'+$dt
- #Provide the size of the disks in GB. It should be greater than the VHD file size.
- $diskSize = '128'
- #Provide the storage type for Managed Disk. PremiumLRS or StandardLRS.
- $storageType = 'Premium_LRS'
- #Get-AzLocation
- $location = 'westeurope'
- $snapshot = Get-AzSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName
- $diskConfig = New-AzDiskConfig -SkuName $storageType -Location $location -CreateOption Copy -SourceResourceId $snapshot.Id -DiskSizeGB $diskSize
- New-AzDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $diskName
- $disk = Get-AzDisk -ResourceGroupName $resourceGroupName -DiskName $diskName
- # swap-os-disk-of-an-azure-vm
- $vmName = 'Auto-Regression-App-Server'
- # Get the VM
- $vm = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
- # Make sure the VM is stopped\deallocated
- $stoppedVm =Stop-AzVM -ResourceGroupName $resourceGroupName -Name $vm.Name -Force
- # Get the new disk that you want to swap in
- $disk = Get-AzDisk -ResourceGroupName $resourceGroupName -Name $diskName
- # Set the VM configuration to point to the new disk
- $setNewDisk =Set-AzVMOSDisk -VM $vm -ManagedDiskId $disk.Id -Name $disk.Name
- # Update the VM with the new OS disk
- $updatedVm = Update-AzVM -ResourceGroupName $resourceGroupName -VM $vm
- # Start the VM
- $startedVm = Start-AzVM -Name $vm.Name -ResourceGroupName $resourceGroupName
Advertisement
Add Comment
Please, Sign In to add comment