vmware / PowerCLI-Example-Scripts

http://blogs.vmware.com/powercli
Other
753 stars 603 forks source link

Add network to instantclone pool doenst work always #456

Closed wesllleyyy closed 3 years ago

wesllleyyy commented 3 years ago

Hello.

I have a script for deploying instant clone pools.

Create Pool

New-HVPool -spec ".\NewPool.json"

Adding the network to the pool doens`t alwats work even with a timer but somethimes its no problem. Does any one now what i am doing wrong( i have got the script from this webiste)

Exception calling "NetworkInterfaceCard_ListBySnapshot" with "1" argument(s): "There is an error in the XML document." At E:\Install\Scripts_6.5\New Scripts 7.13 - 2006\Pools\Instant-Clone\NewPool.ps1:212 char:1

Exception calling "update" with "2" argument(s): "ExceptionType : VMware.Hv.MethodFault ErrorMessage : Missing value for non-optional field nic" At E:\Install\Scripts_6.5\New Scripts 7.13 - 2006\Pools\Instant-Clone\NewPool.ps1:234 char:1


Script

Timer

Function Start-Countdown {
Param( [Int32]$Seconds = 180, [string]$Message = "Pausing for 180 seconds..." ) ForEach ($Count in (1..$Seconds)) { Write-Progress -Id 1 -Activity $Message -Status "Waiting for $Seconds seconds, $($Seconds - $Count) left" -PercentComplete (($Count / $Seconds) * 100) Start-Sleep -Seconds 1 } Write-Progress -Id 1 -Activity $Message -Status "Completed" -PercentComplete 100 -Completed }

Start-Countdown -Seconds 180 -Message "Graag even geduld de pool wordt aangemaakt"

Netwerk

Import-module vmware.hv.helper write-host "Connecting to the connection broker" -ForegroundColor Green try { $hvserver1=connect-hvserver $hvservername -domain $domain -username $username -password $password -WarningAction silentlyContinue -erroraction stop $Services1= $hvServer1.ExtensionData } catch { Write-host "Can't connect to the Connection server please check the credentials." -ForegroundColor Red exit }

$queryService = New-Object VMware.Hv.QueryServiceService $defn = New-Object VMware.Hv.QueryDefinition $defn.queryEntityType = 'DesktopSummaryView' $defn.filter = New-Object VMware.Hv.QueryFilterEquals -property @{'memberName'='desktopSummaryData.name'; 'value' = $poolname} try { $poolid=($queryService.queryservice_create($Services1, $defn)).results } catch { throw "Can't find $poolname, exiting" }

$pool=$Services1.Desktop.desktop_get($poolid.id) $networklabelsall=$services1.networklabel.NetworkLabelListByHostOrCluster($pool.AutomatedDesktopData.VirtualCenterProvisioningSettings.VirtualCenterProvisioningData.hostorcluster) $networklabels=$networklabelsall | where-object {$.data.name -like $labelfilter} $NetworkInterfaceCard=$services1.NetworkInterfaceCard.NetworkInterfaceCard_ListBySnapshot($pool.AutomatedDesktopData.VirtualCenterProvisioningSettings.VirtualCenterProvisioningData.snapshot) $NetworkInterfaceCardSettings=new-object vmware.hv.desktopNetworkInterfaceCardSettings $NetworkInterfaceCardSettings.nic=$NetworkInterfaceCard.id $networkLabelAssignmentSpecs=@()

foreach ($networklabel in $networklabels){ $NetworkLabelAssignmentSpec=new-object VMware.Hv.desktopNetworkLabelAssignmentSpec $NetworkLabelAssignmentSpec.enabled=$True $NetworkLabelAssignmentSpec.networklabel=$networklabel.id $NetworkLabelAssignmentSpec.maxlabeltype="LIMITED" $NetworkLabelAssignmentSpec.MaxLabel=$maxlabels $networkLabelAssignmentSpecs+=$networkLabelAssignmentSpec } $NetworkInterfaceCardSettings.networkLabelAssignmentSpecs=$networkLabelAssignmentSpecs

$VirtualCenterNetworkingSettings=@() $VirtualCenterNetworkingSettings=new-object vmware.hv.DesktopVirtualCenterNetworkingSettings $VirtualCenterNetworkingSettings.nics+=$NetworkInterfaceCardSettings

$desktopService = New-Object VMware.Hv.DesktopService $desktopInfoHelper = $desktopService.read($services1, $Pool.Id) $desktopinfohelper.getAutomatedDesktopDataHelper().getVirtualCenterProvisioningSettingsHelper().setVirtualCenterNetworkingSettingsHelper($VirtualCenterNetworkingSettings) $desktopservice.update($services1, $desktopInfoHelper)

Description

Set-HVPool -PoolName $poolname -key 'base.description' -Value $labelfilter

Enable Provisioning

Set-HVPool -PoolName $poolname -Start