CrazyCoder
CrazyCoder

Reputation: 2388

Not able to Spin a VM in Azure from image

I have to Spin a new VM on Azure from the Image.I have to do this using powershell scripts and not from azure portal. This is the link I'm following to do it.

Now my question is , if I have a VM Image in say Resource Group : ABC and I need to create a VM in Resource Group : XYZ, can it be done? And also I do not have access to Resource Group ABC.

And also where and how do I set my username and password. When we create a new VM from portal, it asks to set username and password. How to do that using powershell.

This is the command I'm trying to use.

New-AzureRmVm `
    -ResourceGroupName "XYZ" `
    -Name "TestVM" `
    -ImageName "Image1" `
    -VirtualNetworkName "VNET1" `
    -SubnetName "Subnet1"

When I run this command , it is giving the below error.

New-AzureRmVm : Can't find the image 'Image1'.
At line:1 char:1
+ New-AzureRmVm `
+ ~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzureRmVM], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.NewAzureVMCommand

Is it because, Image1 is in ABC resource group and not in XYZ. If yes, how do I specify it to map the image fromABC and create VM in XYZ.

Upvotes: 0

Views: 366

Answers (3)

Charles Xu
Charles Xu

Reputation: 31454

As far as I know, there is no way to create a VM yourself if the image in another resource group and you do not have access to the resource group.

If you really want to do that, you can ask the owner of the resource group copy the image to you or give you permission to copy.

You can set the username and password when you create the VM using PowerShell command like this:

$cred = Get-Credential

The result will like this screenshot: enter image description here

New-AzureRmVm `
        -ResourceGroupName "myResourceGroupVM" `
        -Name "myVM" `
        -Location "EastUS" `
        -VirtualNetworkName "myVnet" `
        -SubnetName "mySubnet" `
        -SecurityGroupName "myNetworkSecurityGroup" `
        -PublicIpAddressName "myPublicIpAddress" `
        -Credential $cred

For more details, see Create and Manage Windows VMs with Azure PowerShell.

Upvotes: 0

xavier
xavier

Reputation: 123

Maybe you can store your image in a blob storage and then on creating the VM pass the url of this .VHD file.

To set your own password on create your VM just need this:

$UserName = "example"
$Password = ConvertTo-SecureString "example" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($UserName, $Password)

and then take a look on the following command to specify the config of System Machine Set-AzureRmVMOperatingSystem, there's a parameter to pass the credential object like:

Set-AzureRmVMOperatingSystem -Credential $psCred -VM $configMachine -Windows -ComputerName $nameMachine -EnableAutoUpdate:$false

Upvotes: 1

CHEEKATLAPRADEEP
CHEEKATLAPRADEEP

Reputation: 12788

As per my knowledge, you cannot spin up new VM from image which is present in another resource group.

Note: The image needs to be in the same resource group where you want to create the VM.

Try to create spin up VM in the same resource group where the image is available.

New-AzureRmVm `
    -ResourceGroupName "ABC" `
    -Name "TestVM" `
    -ImageName "Image1" `
    -VirtualNetworkName "VNET1" `
    -SubnetName "Subnet1"

Upvotes: 1

Related Questions