Dave Finds

How to rename a Azure Virtual Machine

Microsoft Azure is a cloud platform with more than 200 products and services that are designed to help you bring new solutions to life and solve today’s challenges by creating a better future. Using azure you can build, run, and manage applications across multiple regions all over the world, backup your on-premises device, and more. Microsoft Azure Virtual Machines (VM) is one of several types of on-demand services, which is scalable and flexible computing resources offered by Microsoft Azure.

Create a Virtual Machine (VM) is very easy, with a few minutes you can create a Virtual Machine (VM) in any of the Azure available regions. To create a Virtual Machine (VM) you do not need to have the technical knowledge or a techie savvy. Because of user-friendly design and structure, anyone can create a VM with the help of any online how-to blogs or video tutorials.

But remaining of Virtual Machine is not easy. When you create a Virtual Machine with a name, Microsoft Azure uses the same name to create Virtual Machine associated services. Despite, so many user requests still Microsoft Azure refuses to offer an easy way to rename its virtual machine. So, How could anyone rename a virtual machine? Till now our changes are to create a new VM by deleting the original VM.

Using the following script you can rename the VM. Read the script carefully and provide your virtual machine details by renaming it. Before proceeding with this process make sure your virtual machine is stopped and deallocated.

 # fill the parameters

    $location="Central US"
    $rgName = "OldVMName"
    $urlOfUploadedImageVhd = "https://portalvhds3wlqfmtd6smlc.blob.core.windows.net/vhds/test-test.vhd"
    $imageName = "NewVMNAme"

    # set the subscription ID

    Select-AzureRmSubscription -SubscriptionId "SubscriptionID"

    $imageConfig = New-AzureRmImageConfig `
    -Location $location

    # Remember to setup the Disk size

    $imageConfig = Set-AzureRmImageOsDisk `
    -Image $imageConfig `
    -OsType Windows `
    -OsState Generalized `
    -BlobUri $urlOfUploadedImageVhd `
    -DiskSizeGB 128

    # Create new Image configuration

    New-AzureRmImage `
    -ImageName $imageName `
    -ResourceGroupName $rgName `
    -Image $imageConfig

    #create a new resourcegroup for the New VM

    New-AzureRMResourceGroup -Name $rgName -Location $location

    #Create the new VM

    New-AzureRmVm `
    -ResourceGroupName $rgName `
    -Name "datacusnet" `
    -ImageName $imageName `
    -Location $location `
    -OpenPorts 3389