willstg / azurefoundation Goto Github PK
View Code? Open in Web Editor NEWThe patterns for a foundational implimenation of Azure Foundation.
License: GNU General Public License v3.0
The patterns for a foundational implimenation of Azure Foundation.
License: GNU General Public License v3.0
The file is broken and cannot be opened
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]
$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
$vm = Add-AzureRmVMNetworkInterface -VM $VM -NetworkInterface $NewNic
$Proceed = Read-host 'Type Yes if you want to proceed'
if($Proceed -eq "Yes"){
Stop-AzureRmVM -Name $VM.Name -ResourceGroupName $Vm.ResourceGroupName -Force
Remove-AzureRmVM -Name $VM.Name -ResourceGroupName $Vm.ResourceGroupName -Force
#Is there an Availability Set?
if($vm.AvailabilitySetReference.id -eq $null){
$newVMConfig = new-azurermvmconfig -VMSize $vm.HardwareProfile.VmSize -VMName $vm.Name -Tags $vm.tags
}
else{
$newVMConfig = new-azurermvmconfig -VMSize $vm.HardwareProfile.VmSize -VMName $vm.Name -AvailabilitySetId $vm.AvailabilitySetReference.Id -Tags $vm.tags
}
Add-AzureRmVMNetworkInterface -vm $newVMConfig -id $vm.NetworkProfile.NetworkInterfaces[0].Id
#Is the VM Windows or Linux?
if($vm.StorageProfile.osDisk.OStype -eq "Windows"){
#Is the VM using Managed Disk or Storage Accounts?
if($vm.storageProfile.OSDisk.ManagedDisk.ID -eq $null){
Set-AzureRmVMOSDisk -vm $newVMConfig -Name $vm.StorageProfile.OsDisk.Name -CreateOption Attach -vhdURI $vm.StorageProfile.OsDisk.Vhd.Uri -Windows
}
else{
$DiskSku = (get-azurermdisk -ResourceGroupName $Vm.ResourceGroupName -Name $vm.StorageProfile.OsDisk.Name).sku.name
Set-AzureRmVMOSDisk -vm $newVMConfig -Name $vm.StorageProfile.OsDisk.Name -CreateOption Attach -ManagedDiskId $vm.StorageProfile.OsDisk.ManagedDisk.Id -StorageAccountType $DiskSku -Windows
}
}
else {
$DiskSku = (get-azurermdisk -ResourceGroupName $Vm.ResourceGroupName -Name $vm.StorageProfile.OsDisk.Name).sku.name
Set-AzureRmVMOSDisk -vm $newVMConfig -Name $vm.StorageProfile.OsDisk.Name -CreateOption Attach -ManagedDiskId $vm.StorageProfile.OsDisk.ManagedDisk.Id -StorageAccountType $DiskSku -Linux
}
#Does the VM have any Data Disks?
if($vm.StorageProfile.DataDisks -ne $null){
foreach($Disk in $VM.StorageProfile.DataDisks){
if($Disk.ManagedDisk -eq $null){
add-AzureRmVMDataDisk -Name $disk.name -Lun $disk.lun -VM $newVMConfig -Caching $disk.caching -CreateOption attach -VhdUri $disk.vhd.Uri
}
else{
$DiskSku = (get-azurermdisk -ResourceGroupName $Vm.ResourceGroupName -Name $Disk.Name).sku.name
add-AzureRmVMDataDisk -Name $disk.name -Lun $disk.lun -VM $newVMConfig -Caching $disk.caching -CreateOption attach -ManagedDiskId $disk.ManagedDisk.Id -StorageAccountType $DiskSku
}
}
}
New-AzureRmVM -ResourceGroupName $vm.ResourceGroupName -Location $vm.Location -VM $newVMConfig -Verbose
}
#}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.