diff --git a/src/Connection/Connect-To.ps1 b/src/Connection/Connect-To.ps1 index cd074bd..6ce3e3e 100644 --- a/src/Connection/Connect-To.ps1 +++ b/src/Connection/Connect-To.ps1 @@ -10,7 +10,7 @@ function Connect-To { Specify the host, for which you would like to change the credentials. .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. .PARAMETER Type @@ -48,28 +48,28 @@ function Connect-To { [None] .EXAMPLE - Connect-To -RemoteHost "ucs.myside.local" -Type CiscoUcs + Connect-To -RemoteHost 'ucs.myside.local' -Type CiscoUcs .EXAMPLE - Connect-To -RemoteHost "ucscentral.myside.local" -Type 'CiscoUcsCentral' + Connect-To -RemoteHost 'ucscentral.myside.local' -Type 'CiscoUcsCentral' .EXAMPLE - Connect-To -RemoteHost "ftp.myside.local" -Type FTP + Connect-To -RemoteHost 'ftp.myside.local' -Type FTP .EXAMPLE - Connect-To -RemoteHost "fas.myside.local" -Type NetAppFAS + Connect-To -RemoteHost 'fas.myside.local' -Type NetAppFAS .EXAMPLE - Connect-To -RemoteHost "esx01.myside.local" -Type VMware + Connect-To -RemoteHost 'esx01.myside.local' -Type VMware .EXAMPLE - Connect-To -RemoteHost "vCenter.myside.local" -Type CisServer + Connect-To -RemoteHost 'vCenter.myside.local' -Type CisServer .EXAMPLE - Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTP + Connect-To -RemoteHost 'exchange01.myside.local' -Type ExchangeHTTP .EXAMPLE - Connect-To -RemoteHost "exchange01.myside.local" -Type ExchangeHTTPS + Connect-To -RemoteHost 'exchange01.myside.local' -Type ExchangeHTTPS #> [CmdletBinding(DefaultParameterSetName = 'Private')] @@ -120,7 +120,7 @@ function Connect-To { begin { # Set the CredentialStore for private, shared or custom mode. - Write-Debug ("ParameterSetName: {0}" -f $PSCmdlet.ParameterSetName) + Write-Debug ('ParameterSetName: {0}' -f $PSCmdlet.ParameterSetName) if ($PSCmdlet.ParameterSetName -eq 'Private') { $Path = Get-DefaultCredentialStorePath } @@ -131,7 +131,7 @@ function Connect-To { } switch ($Type) { - "VMware" { + 'VMware' { # Disable the yellow certificate warning, since we haven't replaced the SSL certs for vCenter/ESXi $null = Set-PowerCLIConfiguration -Scope Session -InvalidCertificateAction Ignore -Confirm:$false @@ -149,8 +149,8 @@ function Connect-To { # Check if $Identifier has been defined, in which case we need to use different name for # the lookup of the CredentialStoreItem. try { - if ($Identifier -ne "") { - $RemoteHostIdentifier = "{0}/{1}" -f $Identifier, $RemoteHost + if ($Identifier -ne '') { + $RemoteHostIdentifier = '{0}/{1}' -f $Identifier, $RemoteHost $creds = Get-CredentialStoreItem -Shared -RemoteHost $RemoteHostIdentifier -Path $Path } else { @@ -161,8 +161,8 @@ function Connect-To { catch { $MessageParams = @{ Message = ( - "Unable to look up credential store item for RemoteHost " + - ("{0}/Identifier {1}!" -f $RemoteHost, $Identifier) + 'Unable to look up credential store item for RemoteHost ' + + ('{0}/Identifier {1}!' -f $RemoteHost, $Identifier) ) ErrorAction = 'Stop' } @@ -173,16 +173,16 @@ function Connect-To { $creds = $Credentials } - if ($creds.UserName -eq "" -or $creds.Password.GetType().Name -ne 'SecureString') { + if ($creds.UserName -eq '' -or $creds.Password.GetType().Name -ne 'SecureString') { $MessageParams = @{ - Message = "Please provide valid credentials for RemoteHost {0}!" -f $RemoteHost + Message = 'Please provide valid credentials for RemoteHost {0}!' -f $RemoteHost ErrorAction = 'Stop' } Write-Error @MessageParams } else { switch ($Type) { - "CiscoUcs" { + 'CiscoUcs' { try { $handle = Connect-Ucs -Name $RemoteHost -Credential $creds -ErrorAction 'Stop' -NotDefault $ExecutionContext.SessionState.PSVariable.Set('DefaultUcs', $handle) @@ -190,13 +190,13 @@ function Connect-To { catch { $MessageParams = @{ - Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type + Message = 'Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type ErrorAction = 'Stop' } Write-Error @MessageParams } } - "CiscoUcsCentral" { + 'CiscoUcsCentral' { try { $handle = Connect-UcsCentral -Name $RemoteHost -Credential $creds -NotDefault $ExecutionContext.SessionState.PSVariable.Set('DefaultUcsCentral', $handle) @@ -210,7 +210,7 @@ function Connect-To { Write-Error @MessageParams } } - "FTP" { + 'FTP' { # First establish the FTP session $WinSCPConParams = @{ Credential = $creds @@ -223,22 +223,22 @@ function Connect-To { $Global:WinSCPSession = New-WinSCPSession -SessionOption $FTPSessionOption } catch { - throw "Could not connect to {0} using {1} protocol!" -f $RemoteHost, $Type + throw 'Could not connect to {0} using {1} protocol!' -f $RemoteHost, $Type } # Check the Connection State if (!($WinSCPSession.Opened)) { # Check the connection state and find out if the session is still open. $MessageParams = @{ Message = ( - ("Connection to {0} using Type {1} " -f $RemoteHost, $Type) + - "was established. But now it seems to be lost!" + ('Connection to {0} using Type {1} ' -f $RemoteHost, $Type) + + 'was established. But now it seems to be lost!' ) ErrorAction = 'Stop' } Write-Error @MessageParams } } - "NetAppFAS" { + 'NetAppFAS' { try { $null = Connect-NcController -Name $RemoteHost -Credential $creds -ErrorAction Stop -HTTPS } @@ -246,13 +246,13 @@ function Connect-To { catch { # Write a error message to the log. $MessageParams = @{ - Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type + Message = 'Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type ErrorAction = 'Stop' } Write-Error @MessageParams } } - "VMware" { + 'VMware' { try { Connect-VIServer -Server $RemoteHost -Credential $creds -ErrorAction Stop | Out-Null } @@ -260,13 +260,13 @@ function Connect-To { catch { # Write a error message to the log. $MessageParams = @{ - Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type + Message = 'Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type ErrorAction = 'Stop' } Write-Error @MessageParams } } - "CisServer" { + 'CisServer' { try { if ($PassThru.IsPresent) { Connect-CisServer -Server $RemoteHost -Credential $creds -ErrorAction Stop @@ -280,16 +280,16 @@ function Connect-To { catch { # Write a error message to the log. $MessageParams = @{ - Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type + Message = 'Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type ErrorAction = 'Stop' } Write-Error @MessageParams } } - "ExchangeHTTP" { + 'ExchangeHTTP' { try { $ConnectionParams = @{ - ConnectionURI = "http://{0}/powershell" -f $RemoteHost + ConnectionURI = 'http://{0}/powershell' -f $RemoteHost ConfigurationName = 'Microsoft.Exchange' Credential = $creds ErrorAction = 'Stop' @@ -301,16 +301,16 @@ function Connect-To { catch { # Write a error message to the log. $MessageParams = @{ - Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type + Message = 'Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type ErrorAction = 'Stop' } Write-Error @MessageParams } } - "ExchangeHTTPS" { + 'ExchangeHTTPS' { try { $ConnectionParams = @{ - ConnectionURI = "https://{0}/powershell" -f $RemoteHost + ConnectionURI = 'https://{0}/powershell' -f $RemoteHost ConfigurationName = 'Microsoft.Exchange' Credential = $creds ErrorAction = 'Stop' @@ -320,13 +320,13 @@ function Connect-To { catch { # Write a error message to the log. $MessageParams = @{ - Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type + Message = 'Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type ErrorAction = 'Stop' } Write-Error @MessageParams } } - "SCP" { + 'SCP' { $WinSCPSessionParams = @{ Credential = $creds Hostname = $RemoteHost @@ -337,13 +337,13 @@ function Connect-To { $SessionOption = New-WinSCPSessionOption @WinSCPSessionParams $Global:WinSCPSession = New-WinSCPSession -SessionOption $SessionOption Write-Verbose -Message ( - "SCP Connection established with {0}" -f $Global:WinSCPSession.Hostname + 'SCP Connection established with {0}' -f $Global:WinSCPSession.Hostname ) } catch { # Write a error message to the log. $MessageParams = @{ - Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type + Message = 'Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type ErrorAction = 'Stop' } Write-Error @MessageParams @@ -353,8 +353,8 @@ function Connect-To { # Check the connection state and find out if the session is still open. $MessageParams = @{ Message = ( - ("Connection to {0} using Type {1} was established. " -f $RemoteHost, $Type) + - "But now it seems to be lost!" + ('Connection to {0} using Type {1} was established. ' -f $RemoteHost, $Type) + + 'But now it seems to be lost!' ) ErrorAction = 'Stop' } @@ -364,7 +364,7 @@ function Connect-To { default { # Write a error message to the log. $MessageParams = @{ - Message = "Unable to connect to {0} using Type {1}." -f $RemoteHost, $Type + Message = 'Unable to connect to {0} using Type {1}.' -f $RemoteHost, $Type ErrorAction = 'Stop' } Write-Error @MessageParams