Skip to content

Instantly share code, notes, and snippets.

@dlinsley
Created March 11, 2017 06:07
Show Gist options
  • Save dlinsley/74f7fc4597099a062365278c072308a6 to your computer and use it in GitHub Desktop.
Save dlinsley/74f7fc4597099a062365278c072308a6 to your computer and use it in GitHub Desktop.
Sample to add vCenter to Horizon View with all available options
<#
Author: Daniel Linsley, @danlinsley
Description: Sample to add vCenter to Horizon View with all available options
#>
Import-Module VMware.VimAutomation.HorizonView
Connect-HVServer -Server "view.corp.local" -User "administrator@vsphere.local" -Pass "yourPassword"
$vc_service = New-Object VMware.Hv.VirtualCenter
#Create a vc_spec for each VirtualCenter you want to add
$vc_spec = New-Object VMware.Hv.VirtualCenterSpec
$vc_spec.DisplayName = "Your vCenter Host"
$vc_spec.Description = "Your vCenter Host for XYZ"
$vc_password = ConvertTo-SecureString "youPassword" -AsPlainText -Force
$vc_spec.ServerSpec = createVcServerSpec("vcenter.corp.local", "administrator@vsphere.local",$vc_password)
$vc_spec.Limits = createVcLimits(20, 50, 30, 30, 20)
# Does not need to be specified
#$vc_spec.CertificateOverride
$vc_spec.StorageAcceleratorData = createVcStorageAcceleratorData($True, 1024)
$vc_spec.SeSparseReclamationEnabled = $True
$vc_spec.ViewComposerData = createViewComposerData("STANDALONE", "viewcomp.corp.local", "admin@vsphere.local", $vc_password)
# Add the vCenter to View:
$vC_Id = $vc_service.VirtualCenter_Create($vc_spec)
###############################################################
function createVcServerSpec($hostName, $username, $password) {
$spec = New-Object VMware.Hv.ServerSpec
$spec.ServerName = $hostName
$spec.Port = 443
$spec.UseSSL = $true
$spec.UserName = $username
$spec.Password = $password
$spec.ServerType = "VIRTUAL_CENTER"
return $spec
}
function createViewComposerServerSpec($hostName, $username, $password) {
$spec = New-Object VMware.Hv.ServerSpec
$spec.ServerName = $hostName
$spec.Port = 18443
$spec.UseSSL = $true
$spec.UserName = $username
$spec.Password = $password
$spec.ServerType = "VIEW_COMPOSER"
return $spec
}
function createVcLimits($vcProvLimit, $vcPowerOpsLimit, $viewProvLimit, $viewMaintLimit, $instaCloneLimit) {
$limits = New-Object VMware.Hv.VirtualCenterConcurrentOperationLimits
$limits.VcProvisioningLimit = $vcProvLimit
$limits.VcPowerOperationsLimit = $vcPowerOpsLimit
$limits.ViewComposerProvisioningLimit = $viewProvLimit
$limits.ViewComposerMaintenanceLimit = $viewMaintLimit
$limits.InstantCloneEngineProvisioningLimit = $instaCloneLimit
return $limits
}
function createVcStorageAcceleratorData($enable, $defaultCacheSizeMB) {
$data = New-Object VMware.Hv.VirtualCenterStorageAcceleratorData
$data.Enabled = $enable
$data.DefaultCacheSizeMB = $defaultCacheSizeMB
return $data
}
function createViewComposerData($type, $hostname, $username, $password) {
$data = New-Object VMware.Hv.VirtualCenterViewComposerData
$data.ViewComposerType = $type #Possible Values: DISABLED, LOCAL_TO_VC, STANDALONE
if ($type -ne "DISABLED") {
$data.ServerSpec = createViewComposerServerSpec($hostname,$username,$password)
}
return $data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment