VMware Cloud Community
virtualhobbit
Enthusiast
Enthusiast
Jump to solution

Auth struggling to add a vCenter to Horizon using PowerCLI - suspect dodgy auth code

Hi everyone,

I'm struggling to add a vCenter to VMware Horizon. Server details, creds etc are good (tested in GUI), but the error I'm getting is:

Exception calling "VirtualCenter_Create" with "1" argument(s): "ExceptionType : VMware.Hv.InvalidRequest

ErrorMessage : {#ERROR_VC_AUTH_NETWORK_CONNECTION#} Failed to add Virtual Center instance."

$spec.ServerSpec.Username="administrator@vsphere.local"

$vcPassword = Read-Host "vCenter User password: " -AsSecureString

$tempPW = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($vcPassword)

$plainVcPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($tempPW)

$vcEncPassword = New-Object VMware.Hv.SecureString

$enc = [system.Text.Encoding]::UTF8

$vcEncPassword.Utf8String = $enc.GetBytes($plainVcPassword)

$spec.ServerSpec.Password = $vcEncPassword

Can I just check - does the above code look right?

Many thanks,

-Mark

0 Kudos
1 Solution

Accepted Solutions
virtualhobbit
Enthusiast
Enthusiast
Jump to solution

For those who come across this later... the auth code is good.

It was the sslCertThumbprintAlgorithm that was tripping me up! All working now.

-Mark

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

I suspect you have an extra 'v' in line 4.

$plainvVcPassword


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

0 Kudos
virtualhobbit
Enthusiast
Enthusiast
Jump to solution

That was typo on my part while tidying it up 😞

This wasn't it unfortunately

0 Kudos
virtualhobbit
Enthusiast
Enthusiast
Jump to solution

For those who come across this later... the auth code is good.

It was the sslCertThumbprintAlgorithm that was tripping me up! All working now.

-Mark

0 Kudos
dwchan
Enthusiast
Enthusiast
Jump to solution

I am using a simple code as you (so I assume is not a password problem, but still running into an error when try to update the $spec.  Any suggestion would be appreicated

Import-Module "VMware.VimAutomation.HorizonView"
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false
$hvFQDN = $strVMName.ToLower()+'.'+$strVMDomain+'.com'
$hv = Connect-HVServer -Server $hvFQDN -Credential $DomainAdminCredential
$hv = $global:DefaultHVServers[0]
$hvServices = $hv.ExtensionData
$a=$hvServices.VirtualCenter.VirtualCenter_List()
$a.serverSpec.Password
# Create required objects
$spec=new-object VMware.Hv.VirtualCenterSpec
$spec.serverspec=new-object vmware.hv.serverspec
$spec.viewComposerData=new-object VMware.Hv.virtualcenterViewComposerData
$spec.Certificateoverride=new-object vmware.hv.CertificateThumbprint
$spec.limits=new-object VMware.Hv.VirtualCenterConcurrentOperationLimits
$spec.storageAcceleratorData=new-object VMware.Hv.virtualcenterStorageAcceleratorData

# vCenter Server specs
$spec.ServerSpec.servername="vcsa.tataoui.com" # Required, fqdn for the vCenter server
$spec.ServerSpec.port=443 # Required
$spec.ServerSpec.usessl=$true # Required
$spec.ServerSpec.username="administrator@vsphere.local" # Required user@domain
$vcpassword=read-host "vCenter User password?" -assecurestring
$temppw = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($vcPassword)
$PlainvcPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($temppw)
$vcencPassword = New-Object VMware.Hv.SecureString
$enc = [system.Text.Encoding]::UTF8
$vcEncPassword.Utf8String = $enc.GetBytes($PlainvcPassword)
$spec.ServerSpec.password=$vcEncPassword
$spec.ServerSpec.servertype="VIRTUAL_CENTER"
# Description & Displayname, neither is required to be set
$spec.description="Desktop Pod vCenter" # Not Required
$spec.displayname="VCSA" # Not Required
$spec.CertificateOverride=($hvServices.Certificate.Certificate_Validate($spec.serverspec)).thumbprint
$spec.CertificateOverride.SslCertThumbprint=($hvServices.Certificate.Certificate_Validate($spec.serverspec)).certificate
$spec.CertificateOverride.sslCertThumbprintAlgorithm="DER_BASE64_PEM"
# Limits
# Only change when you want to change the default values. It is required to set these in the spec
$spec.Limits.vcProvisioningLimit=20
$spec.Limits.VcPowerOperationsLimit=50
$spec.limits.ViewComposerProvisioningLimit=12
$spec.Limits.ViewComposerMaintenanceLimit=20
$spec.Limits.InstantCloneEngineProvisioningLimit=20
# Storage Accelerator data
$spec.StorageAcceleratorData.enabled=$false
#$spec.StorageAcceleratorData.DefaultCacheSizeMB=1024 # Not Required
# Cmposer
# most can be left empty but they need to be set otherwise you'll get a xml error
$spec.ViewComposerData.viewcomposertype="DISABLED" # DISABLED for none, LOCAL_TO_VC for installed with the vcenter and STANDALONE for s standalone composer
if ($spec.ViewComposerData.viewcomposertype -ne "DISABLED"){
$spec.ViewComposerData.ServerSpec=new-object vmware.hv.serverspec
$spec.ViewComposerData.CertificateOverride=new-object VMware.Hv.CertificateThumbprint
$cmppassword=read-host "Composer user password?" -assecurestring
$temppw = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($cmpPassword)
$PlaincmpPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($temppw)
$cmpencPassword = New-Object VMware.Hv.SecureString
$enc = [system.Text.Encoding]::UTF8
$cmpencPassword.Utf8String = $enc.GetBytes($PlaincmpPassword)
$spec.ViewComposerData.ServerSpec.password=$cmpencPassword
$spec.ViewComposerData.ServerSpec.servername="vcsa.tataoui.com"
$spec.ViewComposerData.ServerSpec.port=18443
$spec.ViewComposerData.ServerSpec.usessl=$true
$spec.ViewComposerData.ServerSpec.username="m_wouter@loft.lab"
$spec.ViewComposerData.ServerSpec.servertype="VIEW_COMPOSER"
$spec.ViewComposerData.CertificateOverride=($hvServices.Certificate.Certificate_Validate($spec.ViewComposerData.ServerSpec)).thumbprint
$spec.ViewComposerData.CertificateOverride.sslCertThumbprint = ($hvServices.Certificate.Certificate_Validate($spec.ViewComposerData.ServerSpec)).certificate
$spec.ViewComposerData.CertificateOverride.sslCertThumbprintAlgorithm = "DER_BASE64_PEM"
}
# Disk reclamation, this is required to be set to either $false or $true
$spec.VmcDeployment=$false
$spec.DisableVCInventoryLicenseAlarm=$false
$spec.SeSparseReclamationEnabled=$false
# This will create the connection
$hvServices.VirtualCenter.VirtualCenter_Create($spec)

Exception calling "VirtualCenter_Create" with "1" argument(s): "ExceptionType : VMware.Hv.UnexpectedFault
ErrorMessage : Invalid Type stored in LDAP
CauseString :
CauseStackTrace :
ErrorCode :
ErrorAttributes : "
At line:1 char:9
+ $hvServices.VirtualCenter.VirtualCenter_Create($spec)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

0 Kudos