VMware Cloud Community
alpha_76
Contributor
Contributor
Jump to solution

New-VM command fails with network name

Hey guys,

I'm trying to deploy a new VM using PowerCLI but it keeps failing.

I first tried this.

New-VM -Name "TestVM02" -Datastore "VMFS5_1" -NumCPU 2 -MemoryMB 8192 -DiskGB 1 -DiskStorageFormat Thin -VMHost "esx07.acme.local"

Which threw an error:

PowerCLI could not automatically determine a network to which to attach the VM. Specify a network explicitly using the -NetworkName parameter.

OK, so I then tried:

New-VM -Name "TestVM02" -Datastore "VMFS5_1" -NumCPU 2 -MemoryMB 8192 -DiskGB 1 -DiskStorageFormat Thin -VMHost "esx07.acme.local" -NetworkName "VM Network"

Which also throws an error.

An error occured but the error message cannot be loaded. The error Id is NetworkBackingInfoBuilder_GetNetworkBackingsByName_NonExistentNetworks

I know the network name exists, and I also tried a couple of the others but get the same error.

Not sure what I'm doing wrong??

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

Get-VMHost -PipelineVariable esx |

ForEach-Object -Process {

    Get-VirtualPortGroup -VMHost $esx |

    Select @{N='VMHost';E={$esx.Name}},

        @{N='Portgroup';E={$_.Name}},

        @{N='Type';E={$_.ExtensionData.Gettype().Name}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

Which PowerCLI version and vSphere version are you using?

Does the following return a portgroup?

Get-VirtualPortGroup -Name 'VM Network'

If yes, can you try with

$pg = Get-VirtualPortGroup -Name 'VM Network'

New-VM -Name "TestVM02" -Datastore "VMFS5_1" -NumCPU 2 -MemoryMB 8192 -DiskGB 1 -DiskStorageFormat Thin -VMHost "esx07.acme.local" -Portgroup $pg


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
alpha_76
Contributor
Contributor
Jump to solution

Hey LucD,

Thanks for the reply.

I discovered that the host "esx07" is not associated with that network "VM Network".

Probably should of checked that first :smileyblush:

The command works with the associated network.

Appreciate the response.

Reply
0 Kudos
alpha_76
Contributor
Contributor
Jump to solution

LucD, is there a way to list which networks each host is associated with?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could do something like this

Get-VMHost -PipelineVariable esx |

ForEach-Object -Process {

    Get-VirtualPortGroup -VMHost $esx |

    Select @{N='VMHost';E={$esx.Name}},

        @{N='Portgroup';E={$_.Name}},

        @{N='Type';E={$_.ExtensionData.Gettype().Name}}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
alpha_76
Contributor
Contributor
Jump to solution

Perfect, love your work!