Replace double-quotes with single-quotes

This commit is contained in:
pinguinfuss 2023-03-09 13:08:21 +01:00
parent ddb85d907f
commit 79a1a214c2

View File

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