Implement StorageGRID connection #79

Open
pinguinfuss wants to merge 23 commits from pinguinfuss/PSCredentialStore:ConnectTo-StorageGRID into master
Showing only changes of commit 9ed86fd126 - Show all commits

View File

@ -10,7 +10,7 @@ function Disconnect-From {
Specify the remote endpoint, whose session you would like to terminate. Specify the remote endpoint, whose session you would like to terminate.
.PARAMETER Identifier .PARAMETER Identifier
Defaults to "". Specify a string, which separates two CredentialStoreItems for the Defaults to ''. Specify a string, which separates two CredentialStoreItems for the
same hostname. same hostname.
.PARAMETER Type .PARAMETER Type
@ -18,13 +18,13 @@ function Disconnect-From {
- CiscoUcs - CiscoUcs
- CiscoUcsCentral - CiscoUcsCentral
- FTP
- NetAppFAS
- VMware
- CisServer
- ExchangeHTTP - ExchangeHTTP
- ExchangeHTTPS - ExchangeHTTPS
- FTP
- NetAppFAS
- SCP - SCP
- VMware
- VMwareCisServer
.PARAMETER Force .PARAMETER Force
Force the disconnect, even if the disconnect would fail. Force the disconnect, even if the disconnect would fail.
@ -36,28 +36,28 @@ function Disconnect-From {
[None] [None]
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost "ucs.myside.local" -Type CiscoUcs Disconnect-From -RemoteHost 'ucs.myside.local' -Type CiscoUcs
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost "ftp.myside.local" -Type FTP Disconnect-From -RemoteHost 'ftp.myside.local' -Type FTP
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost "fas.myside.local" -Type NetAppFAS Disconnect-From -RemoteHost 'fas.myside.local' -Type NetAppFAS
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost "esx01.myside.local" -Type VMware Disconnect-From -RemoteHost 'esx01.myside.local' -Type VMware
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost "esx01.myside.local" -Type VMware -Force:$True Disconnect-From -RemoteHost 'esx01.myside.local' -Type VMware -Force:$True
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost "vcenter.myside.local" -Type CisServer Disconnect-From -RemoteHost 'vcenter.myside.local' -Type CisServer
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTP Disconnect-From -RemoteHost 'exchange01.myside.local' -Type ExchangeHTTP
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS Disconnect-From -RemoteHost 'exchange01.myside.local' -Type ExchangeHTTPS
#> #>
[CmdletBinding()] [CmdletBinding()]
@ -74,13 +74,13 @@ function Disconnect-From {
[ValidateSet( [ValidateSet(
'CiscoUcs', 'CiscoUcs',
'CiscoUcsCentral', 'CiscoUcsCentral',
'FTP',
'NetAppFAS',
'VMware',
'CisServer',
'ExchangeHTTP', 'ExchangeHTTP',
'ExchangeHTTPS', 'ExchangeHTTPS',
'SCP' 'FTP',
'NetAppFAS',
'SCP',
'VMware',
'VMwareCisServer'
)] )]
[string]$Type, [string]$Type,
@ -92,7 +92,101 @@ function Disconnect-From {
process { process {
switch -Regex ($Type) { switch -Regex ($Type) {
"VMware" { 'CiscoUcs' {
try {
Disconnect-Ucs -Ucs $RemoteHost
}
catch {
# Write a error message to the log.
$MessageParams = @{
Message = 'Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type
ErrorAction = 'Stop'
}
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'
}
catch {
$MessageParams = @{
Message = 'Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
# Check for an existing WinSCP Session var
'FTP' {
if ($Global:WinSCPSession.Opened) {
Remove-WinSCPSession -WinSCPSession $Global:WinSCPSession
}
else {
$MessageParams = @{
Message = 'There is no open WinSCP Session'
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
# DataONTAP doesn't have a CmdLet `Disconnect-NcController`.
# So we go ahead and clear the CurrentNcController variable.
'NetAppFAS' {
try {
$MessageParams = @{
Message = (
'Setting {0} to `$null, which will disconnect NetAppFAS' -f $Global:CurrentNcController
)
ErrorAction = 'Continue'
}
Write-Verbose @MessageParams
$Global:CurrentNcController = $null
}
catch {
# Write a error message to the log.
$MessageParams = @{
Message = 'Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
'SCP' {
if ($Global:WinSCPSession.Opened) {
Remove-WinSCPSession -WinSCPSession $Global:WinSCPSession
}
else {
$MessageParams = @{
Message = 'There is no open WinSCP Session'
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
'VMware' {
try { try {
if ($Force) { if ($Force) {
Disconnect-VIServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' -Force:$true Disconnect-VIServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' -Force:$true
@ -105,13 +199,14 @@ function Disconnect-From {
catch { catch {
# Write a error message to the log. # Write a error message to the log.
$MessageParams = @{ $MessageParams = @{
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type Message = 'Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type
ErrorAction = 'Stop' ErrorAction = 'Stop'
} }
Write-Error @MessageParams Write-Error @MessageParams
} }
} }
"CisServer" {
'VMwareCisServer' {
try { try {
if ($Force) { if ($Force) {
Disconnect-CisServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' -Force:$true Disconnect-CisServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' -Force:$true
@ -124,106 +219,17 @@ function Disconnect-From {
catch { catch {
# Write a error message to the log. # Write a error message to the log.
$MessageParams = @{ $MessageParams = @{
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type Message = 'Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
# Check for an existing WinSCP Session var
"FTP" {
if ($Global:WinSCPSession.Opened) {
Remove-WinSCPSession -WinSCPSession $Global:WinSCPSession
}
else {
$MessageParams = @{
Message = 'There is no open WinSCP Session'
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
# DataONTAP doesn't have a CmdLet `Disconnect-NcController`.
# So we go ahead and clear the CurrentNcController variable.
"NetAppFAS" {
try {
$MessageParams = @{
Message = (
"Setting {0} to `$null, which will disconnect NetAppFAS" -f $Global:CurrentNcController
)
ErrorAction = 'Continue'
}
Write-Verbose @MessageParams
$Global:CurrentNcController = $null
}
catch {
# Write a error message to the log.
$MessageParams = @{
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
"CiscoUcs" {
try {
Disconnect-Ucs -Ucs $RemoteHost
}
catch {
# Write a error message to the log.
$MessageParams = @{
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
ErrorAction = 'Stop'
}
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' ErrorAction = 'Stop'
} }
Write-Error @MessageParams Write-Error @MessageParams
} }
} }
"ExchangeHTTP*" {
try {
Get-Variable -Name 'PSExchangeRemote' -Scope 'Global' -ErrorAction 'Stop'
Remove-PSSession -Session $Global:PSExchangeRemote -ErrorAction 'Stop'
}
catch {
$MessageParams = @{
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
"SCP" {
if ($Global:WinSCPSession.Opened) {
Remove-WinSCPSession -WinSCPSession $Global:WinSCPSession
}
else {
$MessageParams = @{
Message = 'There is no open WinSCP Session'
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
default { default {
# Write a error message to the log. # Write a error message to the log.
$MessageParams = @{ $MessageParams = @{
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type Message = 'Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type
ErrorAction = 'Stop' ErrorAction = 'Stop'
} }
Write-Error @MessageParams Write-Error @MessageParams