Compare commits

..

No commits in common. "471a372bf9f6cbfed00551a3183d2ec5186d98f1" and "22631f28362865a3777717d4dd13fb52a72b94f1" have entirely different histories.

3 changed files with 160 additions and 196 deletions

View File

@ -22,7 +22,6 @@ function Connect-To {
- ExchangeHTTPS - ExchangeHTTPS
- FTP - FTP
- NetAppFAS - NetAppFAS
- NetAppStorageGRID
- SCP - SCP
- VMware - VMware
- VMwareCisServer - VMwareCisServer
@ -49,32 +48,28 @@ function Connect-To {
[None] [None]
.EXAMPLE .EXAMPLE
Connect-To -RemoteHost 'vc.domain.local' -Type CisServer Connect-To -RemoteHost 'ucs.myside.local' -Type CiscoUcs
.EXAMPLE .EXAMPLE
Connect-To -RemoteHost 'ucs.domain.local' -Type CiscoUcs Connect-To -RemoteHost 'ucscentral.myside.local' -Type 'CiscoUcsCentral'
.EXAMPLE .EXAMPLE
Connect-To -RemoteHost 'ucs-central.domain.local' -Type 'CiscoUcsCentral' Connect-To -RemoteHost 'ftp.myside.local' -Type FTP
.EXAMPLE .EXAMPLE
Connect-To -RemoteHost 'exchange01.domain.local' -Type ExchangeHTTP Connect-To -RemoteHost 'fas.myside.local' -Type NetAppFAS
.EXAMPLE .EXAMPLE
Connect-To -RemoteHost 'exchange01.domain.local' -Type ExchangeHTTPS Connect-To -RemoteHost 'esx01.myside.local' -Type VMware
.EXAMPLE .EXAMPLE
Connect-To -RemoteHost 'ftp.domain.local' -Type FTP Connect-To -RemoteHost 'vCenter.myside.local' -Type CisServer
.EXAMPLE .EXAMPLE
Connect-To -RemoteHost 'fas.domain.local' -Type NetAppFAS Connect-To -RemoteHost 'exchange01.myside.local' -Type ExchangeHTTP
.EXAMPLE .EXAMPLE
Connect-To -RemoteHost 'grid.domain.local' -Type NetAppStorageGRID Connect-To -RemoteHost 'exchange01.myside.local' -Type ExchangeHTTPS
.EXAMPLE
Connect-To -RemoteHost 'esx01.domain.local' -Type VMware
#> #>
[CmdletBinding(DefaultParameterSetName = 'Private')] [CmdletBinding(DefaultParameterSetName = 'Private')]
@ -103,7 +98,6 @@ function Connect-To {
'ExchangeHTTPS', 'ExchangeHTTPS',
'FTP', 'FTP',
'NetAppFAS', 'NetAppFAS',
'NetAppStorageGRID',
'SCP', 'SCP',
'VMware', 'VMware',
'VMwareCisServer' 'VMwareCisServer'
@ -205,7 +199,6 @@ function Connect-To {
Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type) Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type)
} }
} }
'CiscoUcsCentral' { 'CiscoUcsCentral' {
try { try {
$handle = Connect-UcsCentral -Name $RemoteHost -Credential $creds -NotDefault $handle = Connect-UcsCentral -Name $RemoteHost -Credential $creds -NotDefault
@ -216,7 +209,6 @@ function Connect-To {
Write-Error -Message ('Unable to connect to {0} using {1}' -f $RemoteHost, $Type) Write-Error -Message ('Unable to connect to {0} using {1}' -f $RemoteHost, $Type)
} }
} }
'ExchangeHTTP' { 'ExchangeHTTP' {
try { try {
$ConnectionParams = @{ $ConnectionParams = @{
@ -233,7 +225,6 @@ function Connect-To {
Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type) Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type)
} }
} }
'ExchangeHTTPS' { 'ExchangeHTTPS' {
try { try {
$ConnectionParams = @{ $ConnectionParams = @{
@ -248,7 +239,6 @@ function Connect-To {
Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type) Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type)
} }
} }
'FTP' { 'FTP' {
# First establish the FTP session # First establish the FTP session
$WinSCPConParams = @{ $WinSCPConParams = @{
@ -257,7 +247,6 @@ function Connect-To {
Protocol = 'Ftp' Protocol = 'Ftp'
FtpMode = 'Passive' FtpMode = 'Passive'
} }
try { try {
$FTPSessionOption = New-WinSCPSessionOption @WinSCPConParams $FTPSessionOption = New-WinSCPSessionOption @WinSCPConParams
$global:WinSCPSession = New-WinSCPSession -SessionOption $FTPSessionOption $global:WinSCPSession = New-WinSCPSession -SessionOption $FTPSessionOption
@ -274,7 +263,6 @@ function Connect-To {
Write-Error -Message $m Write-Error -Message $m
} }
} }
'NetAppFAS' { 'NetAppFAS' {
# Construct the splatting for Connect-NcController # Construct the splatting for Connect-NcController
$params = @{ $params = @{
@ -302,35 +290,6 @@ function Connect-To {
return $handle return $handle
} }
} }
'NetAppStorageGRID' {
# Construct the splatting for Connect-SgwServer
$params = @{
Name = $RemoteHost
Credential = $creds
SkipCertificateCheck = $true
}
# Check if -PassThru was passed. If so, a) do not set the default variable and b) return the
# session object to the caller.
if ($PSBoundParameters.ContainsKey('PassThru')) {
$params.Add('Transient', $true)
}
try {
$SgwSession = Connect-SgwServer @params
}
catch {
# Write a error message to the log.
Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type)
}
if ($PSBoundParameters.ContainsKey('PassThru')) {
return $SgwSession
}
}
'SCP' { 'SCP' {
$WinSCPSessionParams = @{ $WinSCPSessionParams = @{
Credential = $creds Credential = $creds
@ -357,7 +316,6 @@ function Connect-To {
Write-Error -Message $m Write-Error -Message $m
} }
} }
'VMware' { 'VMware' {
try { try {
Connect-VIServer -Server $RemoteHost -Credential $creds -ErrorAction Stop | Out-Null Connect-VIServer -Server $RemoteHost -Credential $creds -ErrorAction Stop | Out-Null
@ -368,7 +326,6 @@ function Connect-To {
Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type) Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type)
} }
} }
'VMwareCisServer' { 'VMwareCisServer' {
try { try {
if ($PassThru.IsPresent) { if ($PassThru.IsPresent) {
@ -384,6 +341,10 @@ function Connect-To {
Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type) Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type)
} }
} }
default {
# Write a error message to the log.
Write-Error -Message ('Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type)
}
} }
} }
} }

View File

@ -1,26 +1,30 @@
function Disconnect-From { function Disconnect-From {
<# <#
.SYNOPSIS .SYNOPSIS
Terminates a session established with Connect-To. Terminates a session established with Connect-To using a CredentialStoreItem.
.DESCRIPTION .DESCRIPTION
Terminates a session established with Connect-To. Terminates a session established with Connect-To using a CredentialStoreItem.
.PARAMETER RemoteHost .PARAMETER RemoteHost
Specify the remote endpoint, whose session you would like to terminate. Specify the remote endpoint, whose session you would like to terminate.
.PARAMETER Identifier
Defaults to "". Specify a string, which separates two CredentialStoreItems for the
same hostname.
.PARAMETER Type .PARAMETER Type
Specify the host type of the target. Currently implemented targets are: Specify the host type of the target. Currently implemented targets are:
- CiscoUcs - CiscoUcs
- CiscoUcsCentral - CiscoUcsCentral
- ExchangeHTTP
- ExchangeHTTPS
- FTP - FTP
- NetAppFAS - NetAppFAS
- NetAppStorageGRID
- SCP
- VMware - VMware
- VMwareCisServer - CisServer
- ExchangeHTTP
- ExchangeHTTPS
- SCP
.PARAMETER Force .PARAMETER Force
Force the disconnect, even if the disconnect would fail. Force the disconnect, even if the disconnect would fail.
@ -32,45 +36,36 @@ function Disconnect-From {
[None] [None]
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost 'vc.domain.local' -Type CisServer Disconnect-From -RemoteHost "ucs.myside.local" -Type CiscoUcs
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost 'ucs.domain.local' -Type CiscoUcs Disconnect-From -RemoteHost "ftp.myside.local" -Type FTP
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost 'ucs-central.domain.local' -Type 'CiscoUcsCentral' Disconnect-From -RemoteHost "fas.myside.local" -Type NetAppFAS
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost 'exchange01.domain.local' -Type ExchangeHTTP Disconnect-From -RemoteHost "esx01.myside.local" -Type VMware
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost 'exchange01.domain.local' -Type ExchangeHTTPS Disconnect-From -RemoteHost "esx01.myside.local" -Type VMware -Force:$True
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost 'ftp.domain.local' -Type FTP Disconnect-From -RemoteHost "vcenter.myside.local" -Type CisServer
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost 'fas.domain.local' -Type NetAppFAS Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTP
.EXAMPLE .EXAMPLE
Disconnect-From -RemoteHost 'grid.domain.local' -Type NetAppStorageGRID Disconnect-From -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS
.EXAMPLE
Disconnect-From -RemoteHost 'esx01.domain.local' -Type VMware
.EXAMPLE
Disconnect-From -RemoteHost 'esx01.domain.local' -Type VMware -Force:$True
#> #>
[CmdletBinding()] [CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute( [Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidGlobalVars', 'PSAvoidGlobalVars',
'', '',
Justification = 'Wrapping existing global vars from external modules' Justification = 'Wrapping existing global vars from external modules'
)] )]
param ( param (
[Parameter(Mandatory = $true)] [Parameter(Mandatory = $true)]
[string]$RemoteHost, [string]$RemoteHost,
@ -79,14 +74,13 @@ function Disconnect-From {
[ValidateSet( [ValidateSet(
'CiscoUcs', 'CiscoUcs',
'CiscoUcsCentral', 'CiscoUcsCentral',
'ExchangeHTTP',
'ExchangeHTTPS',
'FTP', 'FTP',
'NetAppFAS', 'NetAppFAS',
'NetAppStorageGRID',
'SCP',
'VMware', 'VMware',
'VMwareCisServer' 'CisServer',
'ExchangeHTTP',
'ExchangeHTTPS',
'SCP'
)] )]
[string]$Type, [string]$Type,
@ -94,132 +88,145 @@ function Disconnect-From {
[switch]$Force [switch]$Force
) )
begin { begin {}
# Set sane defaults for Progress, ErrorAction and InformationPreference
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
$InformationPreference = 'Continue'
}
process { process {
switch -Regex ($Type) { switch -Regex ($Type) {
'CiscoUcs' { "VMware" {
try {
$null = Disconnect-Ucs -Ucs $RemoteHost
}
catch {
# Write a error message to the log.
Write-Error -Message ('Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type)
}
}
'CiscoUCSCentral' {
try {
$null = Disconnect-UcsCentral -Name $RemoteHost
$ExecutionContext.SessionState.PSVariable.Set('DefaultUcsCentral', $null)
}
catch {
Write-Error -Message ('Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type)
}
}
'ExchangeHTTP*' {
try {
Get-Variable -Name 'PSExchangeRemote' -Scope 'Global'
Remove-PSSession -Session $global:PSExchangeRemote
}
catch {
Write-Error -Message ('Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type)
}
}
# Check for an existing WinSCP Session var
'FTP' {
if ($global:WinSCPSession.Opened) {
Remove-WinSCPSession -WinSCPSession $global:WinSCPSession
}
else {
Write-Error -Message 'There is no open WinSCP Session'
}
}
# DataONTAP doesn't have a CmdLet `Disconnect-NcController`.
# So we go ahead and clear the CurrentNcController variable.
'NetAppFAS' {
try {
$m = 'Setting {0} to $null, which will disconnect NetAppFAS' -f $global:CurrentNcController
Write-Verbose -Message $m
$global:CurrentNcController = $null
}
catch {
# Write a error message to the log.
Write-Error -Message ('Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type)
}
}
'NetAppSGWS' {
try {
$null = Disconnect-SgwServer -Server $RemoteHost
$null = Remove-Variable -Name CurrentSgwServer -Scope Global -ErrorAction 'SilentlyContinue'
}
catch {
# Write a error message to the log.
Write-Error -Message ('Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type)
}
}
'SCP' {
if ($global:WinSCPSession.Opened) {
Remove-WinSCPSession -WinSCPSession $global:WinSCPSession
}
else {
Write-Error -Message 'There is no open WinSCP Session'
}
}
'VMware' {
# Construct the splatting for Disconnect-VIServer
$params = @{
Server = $RemoteHost
Confirm = $false
}
if ($PSBoundParameters.ContainsKey('Force')) {
$params.Add('Force', $true)
}
try {
$null = Disconnect-VIServer @params
}
catch {
# Write a error message to the log.
Write-Error -Message ('Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type)
}
}
'VMwareCisServer' {
try { try {
if ($Force) { if ($Force) {
$null = Disconnect-CisServer -Server $RemoteHost -Confirm:$false -Force:$true Disconnect-VIServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' -Force:$true
} }
else { else {
$null = Disconnect-CisServer -Server $RemoteHost -Confirm:$false Disconnect-VIServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop'
} }
} }
catch { catch {
# Write a error message to the log. # Write a error message to the log.
Write-Error -Message ('Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type) $MessageParams = @{
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
ErrorAction = 'Stop'
}
Write-Error @MessageParams
}
}
"CisServer" {
try {
if ($Force) {
Disconnect-CisServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop' -Force:$true
}
else {
Disconnect-CisServer -Server $RemoteHost -Confirm:$false -ErrorAction 'Stop'
} }
} }
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
}
}
# 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'
}
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.
Write-Error -Message ('Unable to disconnect from {0} using Type {1}.' -f $RemoteHost, $Type) $MessageParams = @{
Message = "Unable to disconnect from {0} using Type {1}." -f $RemoteHost, $Type
ErrorAction = 'Stop'
}
Write-Error @MessageParams
} }
} }
} }

View File

@ -167,10 +167,6 @@
@{ @{
ModuleName = 'DataONTAP' ModuleName = 'DataONTAP'
ModuleVersion = '9.7.1.1' ModuleVersion = '9.7.1.1'
},
@{
ModuleName = 'StorageGRID-WebScale'
ModuleVersion = '7.2.1'
} }
) )