You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This script will not work anymore due to bug introduced in Powershell, but here is an update that will work around the bug. Specifically, -StorageAccountType must be specified even if managed disk already exists. Also fixed a small issue in the script (missing ".id") for data disks. Finally, removed the pipe from New-AzureRMVM and instead used the -VM parameter for clarity.
Login-AzureRmAccount -Environment $Environment
$subscription = Get-AzureRmSubscription | Out-GridView -Title "Select subscription VMs are located in" -PassThru
Set-AzureRmContext -SubscriptionId $subscription.Id
Write-Host "Successfully logged in to Azure." -ForegroundColor Green
#Limit the VNET migration to a specific Resource Group.
$ResouceGroup = Get-AzureRMResourceGroup | Out-GridView -Title "Select resource group VM(s) are in)" -PassThru
#$VMs= Get-AzureRMVM -ResourceGroupName $ResouceGroup.ResourceGroupName
#Limit the VM migration to a specific VM and just bypass the ForEach below.
$VM = Get-AzureRMVM -ResourceGroupName $ResouceGroup.ResourceGroupName | Out-GridView -Title "Select VM to move" -PassThru
#Foreach($VM in $VMS)
#{
write-output $vm.name + $vm.Location
#Get the current VM's NIC name to get the NIC variable set so the picklist of Subnets will allow the user to have an idea where the NIC was
<# #>
$NicName = (($VM.NetworkProfile.NetworkInterfaces[0].id).Split('/'))[8]
$Nic = Get-AzureRmNetworkInterface -Name $NicName -ResourceGroupName $VM.ResourceGroupName
$Title = (($NIC[0].IpConfigurations.subnet.id).split('/'))[10]
$NewNetwork = Get-AzureRmVirtualNetwork |Select-Object -property Name,Location,ResourceGroupName,AddressSpacetext | Out-GridView -Title "Select VNET to move VM(s) to" -passthru
$NewNetwork = Get-AzureRmVirtualNetwork -Name $NewNetwork.Name -ResourceGroupName $NewNetwork.ResourceGroupName
$NewSubnet = Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $NewNetwork | Select-Object -Property Name,AddressPrefix |Out-GridView -Title "Select subnet to move VM(s) to" -PassThru
$NewSubnet = Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $NewNetwork -Name $NewSubnet.Name
$message = "current name: " + $vm.name + ", Current IP: " +$NIC[0].IpConfigurations.privateIPAddress+ ", Provide a new IP (must be in this prefex): " + $NewSubnet.AddressPrefix
$NewPrivateIP = Read-Host $message
$NewIPConfig = New-AzureRmNetworkInterfaceIpConfig -Subnet $NewSubnet -Name 'config1' -Primary -PrivateIpAddress $NewPrivateIP
$NewNic = New-AzureRmNetworkInterface -Name "$($NicName)1a" -ResourceGroupName $Nic.ResourceGroupName -Location $Nic.Location -IpConfiguration $NewIPConfig -Force
#using the VM Configuration in memory, remove the primary NIC and replace with the new NIC
$VM = Remove-AzureRmVMNetworkInterface -VM $VM -NetworkInterfaceIDs $Nic.Id
This script will not work anymore due to bug introduced in Powershell, but here is an update that will work around the bug. Specifically, -StorageAccountType must be specified even if managed disk already exists. Also fixed a small issue in the script (missing ".id") for data disks. Finally, removed the pipe from New-AzureRMVM and instead used the -VM parameter for clarity.
$Environment = 'AzureCloud'
#$Environment = 'AzureUSGovernment'
Login-AzureRmAccount -Environment $Environment
$subscription = Get-AzureRmSubscription | Out-GridView -Title "Select subscription VMs are located in" -PassThru
Set-AzureRmContext -SubscriptionId $subscription.Id
Write-Host "Successfully logged in to Azure." -ForegroundColor Green
#Limit the VNET migration to a specific Resource Group.
$ResouceGroup = Get-AzureRMResourceGroup | Out-GridView -Title "Select resource group VM(s) are in)" -PassThru
#$VMs= Get-AzureRMVM -ResourceGroupName $ResouceGroup.ResourceGroupName
#Limit the VM migration to a specific VM and just bypass the ForEach below.
$VM = Get-AzureRMVM -ResourceGroupName $ResouceGroup.ResourceGroupName | Out-GridView -Title "Select VM to move" -PassThru
#Foreach($VM in $VMS)
#{
write-output $vm.name + $vm.Location
#Get the current VM's NIC name to get the NIC variable set so the picklist of Subnets will allow the user to have an idea where the NIC was
<# #>
$NicName = (($VM.NetworkProfile.NetworkInterfaces[0].id).Split('/'))[8]
$Nic = Get-AzureRmNetworkInterface -Name $NicName -ResourceGroupName $VM.ResourceGroupName
$Title = (($NIC[0].IpConfigurations.subnet.id).split('/'))[10]
#using the VM Configuration in memory, remove the primary NIC and replace with the new NIC
$VM = Remove-AzureRmVMNetworkInterface -VM $VM -NetworkInterfaceIDs $Nic.Id
#}
The text was updated successfully, but these errors were encountered: