PowerCLI-Example-Scripts icon indicating copy to clipboard operation
PowerCLI-Example-Scripts copied to clipboard

New-HVPool / Set-HVPool Network Settings Instant Clone Powershell Script

Open cradkins opened this issue 6 years ago • 8 comments

Good Morning,

We have a script that will create Instant Clone Desktop Pools in our environment. We're able to alter all of the settings within this script so far, with the exception of the Networks the pool uses. When you deploy an Instant Clone Pool manually, you can either have it default to use the Parent VM's Network, or you can choose as many networks that you want that pool to randomly pick from and assign to the VM's it creates.

Has anyone else run into this, and if so is there a way to use powershell to change the Network Setting within the desktop pool to randomly select from multiple networks?

I did see the -Nic Parameters for the New-HVPool:

-Nics <DesktopNetworkInterfaceCardSettings[]> desktopSpec.automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterNetworkingSettings.nics.

I would imagine that I could do a Set-HVPool with the -key parameter to use the desktopSpec.automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterNetworkingSettings.nics listed above. However, I guess my next question would be would this add multiple Network Cards to each VM, or would it just add multiple networks that the pool can choose from to assign to each VM?

cradkins avatar Feb 07 '19 16:02 cradkins

You cannot add multiple nics to a desktop or to a pool, you can only add one. This setting is used to just set the network to be something other than the default of the master image.

From: cradkins [email protected] Reply-To: vmware/PowerCLI-Example-Scripts [email protected] Date: Thursday, February 7, 2019 at 9:24 AM To: vmware/PowerCLI-Example-Scripts [email protected] Cc: Subscribed [email protected] Subject: [vmware/PowerCLI-Example-Scripts] New-HVPool / Set-HVPool Network Settings Instant Clone Powershell Script (#262)

Good Morning,

We have a script that will create Instant Clone Desktop Pools in our environment. We're able to alter all of the settings within this script so far, with the exception of the Networks the pool uses. When you deploy an Instant Clone Pool manually, you can either have it default to use the Parent VM's Network, or you can choose as many networks that you want that pool to randomly pick from and assign to the VM's it creates.

Has anyone else run into this, and if so is there a way to use powershell to change the Network Setting within the desktop pool to randomly select from multiple networks?

I did see the -Nic Parameters for the New-HVPool:

-Nics <DesktopNetworkInterfaceCardSettings[]> desktopSpec.automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterNetworkingSettings.nics.

I would imagine that I could do a Set-HVPool with the -key parameter to use the desktopSpec.automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterNetworkingSettings.nics listed above. However, I guess my next question would be would this add multiple Network Cards to each VM, or would it just add multiple networks that the pool can choose from to assign to each VM?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/vmware/PowerCLI-Example-Scripts/issues/262, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABK9jJT6pKV-OE-cH6aYv2NGWJ8lUazVks5vLFNUgaJpZM4anqAG.

jackwmc4 avatar Feb 07 '19 16:02 jackwmc4

Good Morning Jack,

We're not trying to add multiple nic's per VM, just have the Instant Clone Pool have 4 potential networks and assign one randomly to each VM.

image

Basically - is there a way to have powershell automatically do what is in the screenshots above that we can do manually? When we use our script, it automatically selects the check box for "use network from current Parent VM Image"

cradkins avatar Feb 07 '19 16:02 cradkins

You would need a pool for each network in that case.

From: cradkins [email protected] Reply-To: vmware/PowerCLI-Example-Scripts [email protected] Date: Thursday, February 7, 2019 at 9:38 AM To: vmware/PowerCLI-Example-Scripts [email protected] Cc: Jack McMichael [email protected], Comment [email protected] Subject: Re: [vmware/PowerCLI-Example-Scripts] New-HVPool / Set-HVPool Network Settings Instant Clone Powershell Script (#262)

Good Morning Jack,

We're not trying to add multiple nic's per VM, just have the Instant Clone Pool have 4 potential networks and assign one randomly to each VM.

[Image removed by sender. image]https://user-images.githubusercontent.com/47366106/52426541-2bea9680-2acc-11e9-8217-56435616f8c8.png

[Image removed by sender. image]https://user-images.githubusercontent.com/47366106/52426600-402e9380-2acc-11e9-93a1-8b09245560ed.png

Basically - is there a way to have powershell automatically do what is in the screenshots above that we can do manually? When we use our script, it automatically selects the check box for "use network from current Parent VM Image"

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/vmware/PowerCLI-Example-Scripts/issues/262#issuecomment-461502640, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABK9jIWCXUr28imE8aip84yckVT3R1CXks5vLFaHgaJpZM4anqAG.

jackwmc4 avatar Feb 07 '19 16:02 jackwmc4

@cradkins The module is not currently equipped to handle this operation. In order to set multiple network labels on a pool, we have to build an object of the type VMware.Hv.NetworkLabelAssignmentSpec assigned to the key desktopSpec.automatedDesktopSpec.virtualCenterProvisioningSettings.virtualCenterNetworkingSettings.networkLabelAssignmentSpecs.

This object contains many nested properties that must be set per network label. (name: type)

  • DesktopNetworkInterfaceCardSettings - VMware.Hv.NetworkLabelAssignmentSpec
    • enabled: boolean
    • networkLabel: VMware.Hv.NetworkLabelId
    • maxLabelType: string ("LIMITED" or "UNLIMITED")
    • maxLabel: int

You could use the -Key and -Value parameters, so long as the value is a properly created object of the type VMware.Hv.NetworkLabelAssignmentSpec

More information from the API DesktopNetworkCardSettings - contains information about how the network label assignment is performed when this feature is enabled.

DesktopNetworkLabelAssignmentSpec - Contains the information needed to create the DesktopNetworkLabelAssignmentSpec[] object.

CajunBard avatar Feb 08 '19 03:02 CajunBard

If you change a pool with the json file it is possible for instant clones to select multiple portgroups. I have created a script that uses the networklabelassignment spec in a blogpost: https://www.retouw.nl/powercli/multi-vlan-network-for-horizon-view-using-powercli-apis/ that method should work for both instant and linked clones

Magneet avatar Feb 12 '19 07:02 Magneet

We have the same issue with New-HVPool when only a single network port group has been selected. The json file dumped for an existing pool does contain the network information, but it is not restored when using that same file to restore a pool.

bfett20 avatar Feb 17 '20 14:02 bfett20

Whats wrong in below foreach

csv

pool desktop
tst1 rtyui
tst2 dfgty

$test = import-csv C:\Users\tst\Desktop\pool.csv

$test1=@($test)

foreach($ts in $test1)

{ New-HVPool -InstantClone -PoolName "$ts.pool" -PoolDisplayName "$ts.pool" -Description "create testpoolps" -UserAssignment FLOATING -Vcenter vc.tst.com -ParentVM 'testvm' -SnapshotVM '12' -VmFolder 'Desktops' -HostOrCluster '11a' -ResourcePool 'Desktops' -NamingMethod PATTERN -D00893TB' -NamingPattern "$ts.desktop" -NetBiosName eentst -DomainAdmin root

}

Exception calling "Desktop_Create" with "2" argument(s): "ExceptionType : VMware.Hv.InvalidArgument ErrorMessage : Invalid value for member ParameterName : base.name" At C:\Program Files\WindowsPowerShell\Modules\VMware.Hv.Helper\VMware.HV.Helper.psm1:4986 char:7

  •   $id = $desktop_helper.Desktop_create($services,$desktopSpecObj)
    
  •   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : VimException

Christosvv avatar Aug 30 '21 07:08 Christosvv

Hi Guys, I am trying to change the port group of my instant clone pool using powershell script but unable to do so. It takes the same portgroup as that of parent image. I really need help in this.

dsharma0814 avatar May 15 '24 06:05 dsharma0814