-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMigrateClassicToARM.ps1
83 lines (63 loc) · 3.81 KB
/
MigrateClassicToARM.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-ps-migration-classic-resource-manager
# https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-migration-classic-resource-manager-deep-dive
# If you don't have the Azure PowerShell modules, run the following on your Win 8+ machine as an administrator
Install-Module Az
Install-Module Azure
# Login to Azure Subscription (Need both Classic and ARM context)
Login-AzAccount
Add-AzureAccount
# If using Azure Cloud Shell, you can authenticate via the following for Classic (Won't work if MFA is enabled)
#Install-Module Azure
#$secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force
#$mycreds = New-Object System.Management.Automation.PSCredential("[email protected]", $secpasswd)
#Add-AzureAccount -Credential $mycreds
# Set default subscription for both environments
Get-AzSubscription
Get-AzSubscription -SubscriptionId XXXXXXXXXXXXXXXXXXXX | Set-AzContext
Select-AzureSubscription -SubscriptionId XXXXXXXXXXXXXXXXXXXX
# Register the namespace - note this may take up to 5 mins
Register-AzResourceProvider -ProviderNamespace Microsoft.ClassicInfrastructureMigrate
# Verify registration was a success, should see "Registered"
Get-AzResourceProvider -ProviderNamespace Microsoft.ClassicInfrastructureMigrate
# Migrate the network and VMs
# Validate the VNET
Move-AzureVirtualNetwork -Validate -VirtualNetworkName $vnetName
(Move-AzureVirtualNetwork -Validate -VirtualNetworkName $vnetName).ValidationMessages
# Prepare the VNET (can take a few minutes to generate shadow resources)
Move-AzureVirtualNetwork -Prepare -VirtualNetworkName $vnetName
# Abort migration if things don't look right
# Move-AzureVirtualNetwork -Abort -VirtualNetworkName $vnetName
# Migrate the VNET
Move-AzureVirtualNetwork -Commit -VirtualNetworkName $vnetName
## Prepare Azure Storage Account for migration
# FYI: don't enable disk encryption after this if going to managed storage
$storageAccountName = "myStorageAccount"
Move-AzureStorageAccount -Prepare -StorageAccountName $storageAccountName
# Commit Azure Storage Account to migrate
Move-AzureStorageAccount -Commit -StorageAccountName $storageAccountName
## Migrate to managed storage
## https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-migrate-to-managed-disks
# Migrate cloud services without a VNET to the new environments
$existingVnetRGName = "myResourceGroup"
$vnetName = "myVirtualNetwork"
$subnetName = "mySubNet"
$serviceName = "myCloudService"
$deploymentName = $serviceName
# Validate the migration
$validate = Move-AzureService -Validate -ServiceName $serviceName `
-DeploymentName $deploymentName -UseExistingVirtualNetwork -VirtualNetworkResourceGroupName $existingVnetRGName -VirtualNetworkName $vnetName -SubnetName $subnetName
$validate.ValidationMessages
# Prepare the migration
Move-AzureService -Prepare -ServiceName $serviceName -DeploymentName $deploymentName `
-UseExistingVirtualNetwork -VirtualNetworkResourceGroupName $existingVnetRGName `
-VirtualNetworkName $vnetName -SubnetName $subnetName
# Abort migration if things don't look right
# Move-AzureService -Abort -ServiceName $serviceName -DeploymentName $deploymentName
# Migrate the cloud serviceName
Move-AzureService -Commit -ServiceName $serviceName -DeploymentName $deploymentName
###############################################
# Troubleshooting
###############################################
# Commands to replace/upgrade Diagnostics extension due to it being unresponsive
Get-AzureVMExtension -VM $VM -ExtensionName LinuxDiagnostic -Publisher Microsoft.Azure.Diagnostics
Set-AzureVMExtension -VM $VM -Publisher 'Microsoft.Azure.Diagnostics' -ExtensionName LinuxDiagnostic -Version 3.0 | Update-AzureVM