$resourceGroupName = 'rg-OMS'
$location = 'eastus2'
$vmName = 'x007'
$snapshotName = 'snapX007disk'
$diskAccountType='Premium_LRS'
$osDiskName = 'newX007fromSnapshot'
$vm = get-azurermvm -ResourceGroupName $resourceGroupName -Name $vmName
$snapshot = New-AzureRmSnapshotConfig -SourceUri $vm.StorageProfile.OsDisk.ManagedDisk.Id -Location $location -CreateOption copy -SkuName $diskAccountType
# create a snapshot
New-AzureRmSnapshot -Snapshot $snapshot -SnapshotName $snapshotName -ResourceGroupName $resourceGroupName
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName
$diskConfig = New-AzureRmDiskConfig -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy -SkuName $diskAccountType
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName
# list all disks
Get-AzureRmDisk -ResourceGroupName $ResourceGroupName | Format-Table -Property Name
# Get the VM
$vm = Get-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName
# Make sure the VM is stopped\deallocated
Stop-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vm.Name -Force
# Get the new disk that you want to swap in
$disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName -Name $osDiskName
# Set the VM configuration to point to the new disk
Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $disk.Id -Name $disk.Name
# Update the VM with the new OS disk
Update-AzureRmVM -ResourceGroupName $resourceGroupName -VM $vm
# Start the VM
Start-AzureRmVM -Name $vm.Name -ResourceGroupName $resourceGroupName
$location = 'eastus2'
$vmName = 'x007'
$snapshotName = 'snapX007disk'
$diskAccountType='Premium_LRS'
$osDiskName = 'newX007fromSnapshot'
$vm = get-azurermvm -ResourceGroupName $resourceGroupName -Name $vmName
$snapshot = New-AzureRmSnapshotConfig -SourceUri $vm.StorageProfile.OsDisk.ManagedDisk.Id -Location $location -CreateOption copy -SkuName $diskAccountType
# create a snapshot
New-AzureRmSnapshot -Snapshot $snapshot -SnapshotName $snapshotName -ResourceGroupName $resourceGroupName
$snapshot = Get-AzureRmSnapshot -ResourceGroupName $resourceGroupName -SnapshotName $snapshotName
$diskConfig = New-AzureRmDiskConfig -Location $snapshot.Location -SourceResourceId $snapshot.Id -CreateOption Copy -SkuName $diskAccountType
$disk = New-AzureRmDisk -Disk $diskConfig -ResourceGroupName $resourceGroupName -DiskName $osDiskName
# list all disks
Get-AzureRmDisk -ResourceGroupName $ResourceGroupName | Format-Table -Property Name
# Get the VM
$vm = Get-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vmName
# Make sure the VM is stopped\deallocated
Stop-AzureRmVM -ResourceGroupName $resourceGroupName -Name $vm.Name -Force
# Get the new disk that you want to swap in
$disk = Get-AzureRmDisk -ResourceGroupName $resourceGroupName -Name $osDiskName
# Set the VM configuration to point to the new disk
Set-AzureRmVMOSDisk -VM $vm -ManagedDiskId $disk.Id -Name $disk.Name
# Update the VM with the new OS disk
Update-AzureRmVM -ResourceGroupName $resourceGroupName -VM $vm
# Start the VM
Start-AzureRmVM -Name $vm.Name -ResourceGroupName $resourceGroupName
Comments
Post a Comment