VMware Cloud Community
HNNY5067
Contributor
Contributor
Jump to solution

How to set the Connection Type using New-VirtualPortGroup

Using PowerCLI 4.1, is there are way to set the port group connection type (Virtual Machine or VMKernel) when you create the Port Group?

thank you

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, try it like this.

$VMHostObj = Get-VMHost $ESXHost
$vsw = get-virtualswitch -name vSwitch0 -VMHost $VMHostObj

New-VMhostNetworkAdapter -VMHost $VMHostObj -VirtualSwitch $vsw -PortGroup "VMotion" -IP 10.110.40.43 -SubnetMask 255.255.255.0 -VMotionEnabled:$true

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

The New-VirtualPortGroup cmdlet can only create Virtual Machine portgroups.

If you want to create a VMKernel or Console portgroup, you have to use the New-VMHostNetworkAdapter cmdlet.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
HNNY5067
Contributor
Contributor
Jump to solution

thanks LucD

I'm using ESXi 4.0

you have pointed me in the right direction however the command (in the form I am using) is not working. Here's what I have tried from the POwerCLI 4.1:

$ESXHost = "servername.domain.local"

Connect-VIServer $ESXHost

$VMHostObj = Get-VMHost $ESXHost

$VMHostObj | get-virtualswitch -name vSwitch0 | New-VMhostNetworkAdapter -PortGroup "VMotion" -IP 10.110.40.43 -VMotionEnabled

I also need to set the VLAN on this portgroup however I did not see an option - at least using this command

thank you

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You should be able to use the Set-VirtualPortGroup cmdlet for setting the VLAN.

Set-VirtualPortgroup -Name <portgroupname> -VlanId <vlanid>

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
HNNY5067
Contributor
Contributor
Jump to solution

Ok thanks, however I cannot get the initial cmdlet that you provided to work - please see my syntax for New-VMHostNetworkAdapter

thanks again

0 Kudos
LucD
Leadership
Leadership
Jump to solution

The -VMotionEnabled parameter is a switch and there is no default value, so you will have to set it to $true explicitely

$ESXHost = "servername.domain.local"
Connect-VIServer $ESXHost
$VMHostObj = Get-VMHost $ESXHost
$VMHostObj | get-virtualswitch -name vSwitch0 | New-VMhostNetworkAdapter -PortGroup "VMotion" -IP 10.110.40.43 -VMotionEnabled:$true

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
HNNY5067
Contributor
Contributor
Jump to solution

I am receiving the following error, which looks to be referring to the VMotionEnabled switch

I executed peryour example in this thread

New-VMHostNetworkAdapter : Missing an argument for parameter 'VMotionEnabled'.

Specify a parameter of type 'System.Nullable`1[http://System.Boolean|http://System.Boolean]' and try again.

At line:1 char:127

+ $VMHostObj | get-virtualswitch -name vSwitch0 | New-VMhostNetworkAdapter -Por

tGroup "VMotion" -IP 10.110.40.43 -VMotionEnabled &lt;&lt;&lt;&lt; ;$true

+ CategoryInfo : InvalidArgument: (Smiley Happy ,

ParameterBindingException

+ FullyQualifiedErrorId : MissingArgument,VMware.VimAutomation.ViCore.Cmdl

ets.Commands.Host.NewVMHostNetworkAdapter

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That's my mistake. A typo, the semicolon after the switch should be a colon.

I updated the lines above.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
HNNY5067
Contributor
Contributor
Jump to solution

thanks LucD

The VMotion error was cleared up however now it is complaining about my usage of pipelines (I think)

New-VMHostNetworkAdapter : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the iput and its properties do not match any of the parameters that take pipeline input.

At line:1 char:73

+ $VMHostObj | get-virtualswitch -name vSwitch0 | New-VMhostNetworkAdapter &lt;&lt;&lt;&lt;

-PortGroup "VMotion" -IP 10.110.40.43 -VMotionEnabled:$true

+ CategoryInfo : InvalidArgument: (vSwitch0:PSObject) [New-VMHost

NetworkAdapter], ParameterBindingException

+ FullyQualifiedErrorId : InputObjectNotBound,VMware.VimAutomation.ViCore.

Cmdlets.Commands.Host.NewVMHostNetworkAdapter

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, try it like this.

$VMHostObj = Get-VMHost $ESXHost
$vsw = get-virtualswitch -name vSwitch0 -VMHost $VMHostObj

New-VMhostNetworkAdapter -VMHost $VMHostObj -VirtualSwitch $vsw -PortGroup "VMotion" -IP 10.110.40.43 -SubnetMask 255.255.255.0 -VMotionEnabled:$true

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
HNNY5067
Contributor
Contributor
Jump to solution

thanks LucD - that worked!

0 Kudos