Add support for quick disconnect to Disconnect-SsoAdminServer

In case one is connected just to one SSO server the cmdlet does not
need to take the -server parameter as it will be discovered from
$DefaultSsoAdminServers. In case there are more than 1 SSO servers
it will not disconnect any connection, instead it will ask to be more
precise using the Server parameter.
This commit is contained in:
Grzegorz Kulikowski
2020-10-05 20:28:40 +02:00
parent b03c1a536d
commit ca508570fb

View File

@@ -147,7 +147,7 @@ function Connect-SsoAdminServer {
} }
function Disconnect-SsoAdminServer { function Disconnect-SsoAdminServer {
<# <#
.NOTES .NOTES
=========================================================================== ===========================================================================
Created on: 9/29/2020 Created on: 9/29/2020
@@ -167,18 +167,45 @@ function Disconnect-SsoAdminServer {
Disconnect a SSO Admin connection stored in 'mySsoAdminConnection' varaible Disconnect a SSO Admin connection stored in 'mySsoAdminConnection' varaible
#> #>
[CmdletBinding()] [CmdletBinding()]
param( param(
[Parameter( [Parameter(
Mandatory=$true, ValueFromPipeline = $true,
ValueFromPipeline=$true, ValueFromPipelineByPropertyName = $false,
ValueFromPipelineByPropertyName=$false, HelpMessage = 'SsoAdminServer object')]
HelpMessage='SsoAdminServer object')] [ValidateNotNull()]
[ValidateNotNull()] [VMware.vSphere.SsoAdminClient.DataTypes.SsoAdminServer]
[VMware.vSphere.SsoAdminClient.DataTypes.SsoAdminServer] $Server
$Server) )
Process { Process {
if (-not $PSBoundParameters['Server']) {
switch (@($global:DefaultSsoAdminServers).count) {
{ $_ -eq 1 } { $server = ($global:DefaultSsoAdminServers).ToArray()[0] ; break }
{ $_ -gt 1 } {
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
([System.ApplicationException]"Connected to more than 1 SSO server, please specify a SSO server via -Server parameter"),
'Disconnect-SsoAdminServer.ConnectedToMoreThanOneSSO',
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$global:DefaultSsoAdminServers
)
)
break
}
Default {
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
([System.ApplicationException]"Not connected to SSO server."),
'Disconnect-SsoAdminServer.NotConnectedToSSO',
[System.Management.Automation.ErrorCategory]::ConnectionError,
$global:DefaultSsoAdminServers
)
)
}
}
}
if ($global:DefaultSsoAdminServers.Contains($Server)) { if ($global:DefaultSsoAdminServers.Contains($Server)) {
$global:DefaultSsoAdminServers.Remove($Server) | Out-Null $global:DefaultSsoAdminServers.Remove($Server) | Out-Null
} }