Contributor
Contributor

New-VM command fails with network name

Jump to solution

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
Leadership
Leadership

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

0 Kudos
5 Replies
Leadership
Leadership

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

0 Kudos
Contributor
Contributor

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.

0 Kudos
Contributor
Contributor

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

0 Kudos
Leadership
Leadership

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

0 Kudos
Contributor
Contributor

Perfect, love your work!