From f2ed54ce34b93370265824fb6ac3864937eaab23 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 19 Jul 2022 14:18:24 +0200 Subject: [PATCH] add CiscoUCSCentral --- src/Connection/Connect-To.ps1 | 29 ++++++++++++++++++++- src/Connection/Disconnect-From.ps1 | 42 +++++++++++++++++++++++------- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/Connection/Connect-To.ps1 b/src/Connection/Connect-To.ps1 index 5c198a3..b14ffc5 100644 --- a/src/Connection/Connect-To.ps1 +++ b/src/Connection/Connect-To.ps1 @@ -15,7 +15,16 @@ function Connect-To { .PARAMETER Type Specify the host type of the target. Currently implemented targets are: Possible connection values are: - CiscoUcs, FTP, NetAppFAS, VMware, CisServer, ExchangeHTTP, ExchangeHTTPS, SCP. + + - CiscoUcs + - CiscoUcsCentral + - CisServer + - ExchangeHTTP + - ExchangeHTTPS + - FTP + - NetAppFAS + - SCP + - VMware .PARAMETER Credentials Use this parameter to bypass the stored credentials. Without this parameter Connect-To tries to read the @@ -41,6 +50,9 @@ function Connect-To { .EXAMPLE Connect-To -RemoteHost "ucs.myside.local" -Type CiscoUcs + .EXAMPLE + Connect-To -RemoteHost "ucscentral.myside.local" -Type 'CiscoUcsCentral' + .EXAMPLE Connect-To -RemoteHost "ftp.myside.local" -Type FTP @@ -79,6 +91,7 @@ function Connect-To { [Parameter(Mandatory = $true, ParameterSetName = 'Private')] [ValidateSet( 'CiscoUcs', + 'CiscoUcsCentral', 'FTP', 'NetAppFAS', 'VMware', @@ -189,6 +202,20 @@ function Connect-To { Write-Error @MessageParams } } + "CiscoUcsCentral" { + try { + $handle = Connect-UcsCentral -Name $RemoteHost -Credential $creds -NotDefault + $ExecutionContext.SessionState.PSVariable.Set('DefaultUcsCentral', $handle) + } + + catch { + $MessageParams = @{ + Message = ('Unable to connect to {0} using {1}' -f $RemoteHost, $Type) + ErrorAction = 'Stop' + } + Write-Error @MessageParams + } + } "FTP" { # First establish the FTP session $WinSCPConParams = @{ diff --git a/src/Connection/Disconnect-From.ps1 b/src/Connection/Disconnect-From.ps1 index a78ae1f..ef8b157 100644 --- a/src/Connection/Disconnect-From.ps1 +++ b/src/Connection/Disconnect-From.ps1 @@ -14,8 +14,17 @@ function Disconnect-From { same hostname. .PARAMETER Type - Specify the host type of the target. Currently implemented targets are: CiscoUcs, FTP, NetAppFAS, VMware, - CisServer, ExchangeHTTP, ExchangeHTTPS, SCP. + Specify the host type of the target. Currently implemented targets are: + + - CiscoUcs + - CiscoUcsCentral + - FTP + - NetAppFAS + - VMware + - CisServer + - ExchangeHTTP + - ExchangeHTTPS + - SCP .PARAMETER Force Force the disconnect, even if the disconnect would fail. @@ -64,6 +73,7 @@ function Disconnect-From { [Parameter(Mandatory = $true)] [ValidateSet( 'CiscoUcs', + 'CiscoUcsCentral', 'FTP', 'NetAppFAS', 'VMware', @@ -85,10 +95,10 @@ function Disconnect-From { "VMware" { try { if ($Force) { - Disconnect-VIServer -Server $RemoteHost -Confirm:$false -ErrorAction Stop -Force:$true + Disconnect-VIServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' -Force:$true } else { - Disconnect-VIServer -Server $RemoteHost -Confirm:$false -ErrorAction Stop + Disconnect-VIServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' } } @@ -104,10 +114,10 @@ function Disconnect-From { "CisServer" { try { if ($Force) { - Disconnect-CisServer -Server $RemoteHost -Confirm:$false -ErrorAction Stop -Force:$true + Disconnect-CisServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' -Force:$true } else { - Disconnect-CisServer -Server $RemoteHost -Confirm:$false -ErrorAction Stop + Disconnect-CisServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' } } @@ -171,10 +181,24 @@ function Disconnect-From { Write-Error @MessageParams } } + "CiscoUCSCentral" { + try { + $handle = Connect-UcsCentral -Name $RemoteHost -Credential $creds -NotDefault + $ExecutionContext.SessionState.PSVariable.Set('DefaultUcsCentral', $handle) + } + catch { + $MessageParams = @{ + Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type + ErrorAction = 'Stop' + } + Write-Error @MessageParams + } + } + "ExchangeHTTP*" { try { - Get-Variable -Name 'PSExchangeRemote' -Scope Global -ErrorAction Stop - Remove-PSSession -Session $Global:PSExchangeRemote -ErrorAction Stop + Get-Variable -Name 'PSExchangeRemote' -Scope 'Global' -ErrorAction 'Stop' + Remove-PSSession -Session $Global:PSExchangeRemote -ErrorAction 'Stop' } catch { $MessageParams = @{ @@ -206,6 +230,4 @@ function Disconnect-From { } } } - - end {} }