Giter VIP home page Giter VIP logo

azurefoundation's People

Contributors

scottstout avatar willstg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azurefoundation's Issues

Script does not work -- here is working update

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

}

#}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.