Closed yanlu2 closed 2 years ago
Could there be extra lines or incorrect server names in your vcentertestlist.txt text file? I'm able to Connect & Disconnect without any sort of error message.
PS C:\Users\Administrator> Connect-SsoAdminServer -Server vc1.example.com -User administrator@vsphere.local -Password VMware1! -SkipCertificateCheck
Name : vc1.example.com
ServiceUri : https://core-vcenter01.lab.enterpriseadmins.org/sso-adminserver/sdk/vsphere.local
User : administrator@vsphere.local
Id : /SsoAdminServer=vsphere.local/administrator@vc1.example.com
IsConnected : True
Client : VMware.vSphere.SsoAdminClient.SsoAdminClient
RefCount : 1
PS C:\Users\Administrator> Disconnect-SsoAdminServer -Server vc1.example.com
PS C:\Users\Administrator> $global:DefaultSsoAdminServers
I even made a simple test loop and the Disconnect works fine there too:
foreach ($vcenter in 'vc1.example.com','vc2.example.com') {
"Attempting to connect to $vcenter"
$thisConnection = Connect-SsoAdminServer -Server $vcenter -User administrator@vsphere.local -Password VMware1! -SkipCertificateCheck
"Attempting to disconnect from $vcenter"
Disconnect-SsoAdminServer -Server $vcenter
"Done"
"===================="
}
The output of the loop doesn't display any sort of error:
Attempting to connect to vc1.example.com
Attempting to disconnect from vc1.example.com
Done
====================
Attempting to connect to vc2.example.com
Attempting to disconnect from vc2.example.com
Done
====================
Thanks Brain, It works if I put .trim() behind of $server.
Foreach ($server in $vcenterlist) { $hostname=$server.Split(".")[0] $rptfile=$path+"usrimpt-"+$hostname+".txt" write-host "`nConnecting to vCenter SSO server $server" Connect-SsoAdminServer -Server $server -User $username -Password $passwd -SkipCertificateCheck
Disconnect-SsoAdminServer -Server $server.Trim()
}
And I more like the answer at #533,
Foreach ($server in $vcenterlist) { $hostname=$server.Split(".")[0] $rptfile=$path+"usrimpt-"+$hostname+".txt" write-host "`nConnecting to vCenter SSO server $server" $serverConnection = Connect-SsoAdminServer -Server $server -User $username -Password $passwd -SkipCertificateCheck
Disconnect-SsoAdminServer -Server $serverConnection
}
Many thanks,
Regards, -Yan
Describe the bug
I've trying to configure a AD over LDAPs Identity source with connect-ssoadminServer command. I used command Disconnect-SsoAdminServer at end but it failed. and it failed in my other scripts. the srcipt I'm using in vCenter-adding-AD-LDAPs.ps1 is
$path="C:\Temp\Reports\vCenters\" # file location
$server="server.comp.com" # VC server
$username = "administrator@vsphere.local" $passwd = password $localdomain="vsphere.local" $corpdomain="corp.comp.com" $vcenterfile=$path+"vcentertestlist.txt" $vcenterlist = get-content $vcenterfile
Foreach ($server in $vcenterlist) { $hostname=$server.Split(".")[0] $rptfile=$path+"usrimpt-"+$hostname+".txt"
}
And output is
PS C:\Users\luy13> C:\PS_scripts\vCenter\vCenter-adding-AD-LDAPs.ps1
Press any key to continue add AD over LDAPs to vCenter server.corp.comp.com:
Name : server.corp.comp.com ServiceUri : https://server.corp.comp.com/sso-adminserver/sdk/vsphere.local User : administrator@vsphere.local Id : /SsoAdminServer=vsphere.local/administrator@server.corp.comp.com IsConnected : True Client : VMware.vSphere.SsoAdminClient.SsoAdminClient RefCount : 1
Disconnect-SsoAdminServer : Cannot process argument transformation on parameter 'Server'. Cannot convert the "server.corp.comp.com" value of type "System.String" to type "VMware.vSphere.SsoAdminClient.DataTypes.SsoAdminServer[]". At C:\PS_scripts\vCenter\vCenter-adding-AD-LDAPs.ps1:30 char:39
Reproduction steps
Expected behavior
should be no error after run Disconnect-ssoadminserver command
Additional context
No response