diff --git a/src/Certificate/New-CSCertAttribute.ps1 b/src/Certificate/New-CSCertAttribute.ps1 index cf5c77f..ba2c368 100644 --- a/src/Certificate/New-CSCertAttribute.ps1 +++ b/src/Certificate/New-CSCertAttribute.ps1 @@ -1,9 +1,4 @@ function New-CSCertAttribute { - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseShouldProcessForStateChangingFunctions', - '', - Justification = 'Returns a new object and does not change data' - )] <# .SYNOPSIS Creates required data for a certificate signing request. @@ -51,6 +46,11 @@ function New-CSCertAttribute { #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseShouldProcessForStateChangingFunctions', + '', + Justification = 'Returns a new object and does not change data' + )] [OutputType('PSCredentialStore.Certificate.Attribute')] param ( [Parameter(Mandatory = $true)] diff --git a/src/Connection/Connect-To.ps1 b/src/Connection/Connect-To.ps1 index 815cd08..be7b048 100644 --- a/src/Connection/Connect-To.ps1 +++ b/src/Connection/Connect-To.ps1 @@ -61,6 +61,11 @@ function Connect-To { #> [CmdletBinding(DefaultParameterSetName = 'Private')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidGlobalVars', + '', + Justification = 'Wrapping existing var from WinSCP module.' + )] param ( [Parameter(Mandatory = $true, ParameterSetName = 'Shared')] [Parameter(Mandatory = $true, ParameterSetName = 'Private')] @@ -114,7 +119,9 @@ function Connect-To { # First check the optional modules if (-not (Resolve-Dependency -Name $Type)) { - Write-Error -Message ("Could not resolve the optional dependencies defined for {0}" -f $Type) -ErrorAction 'Stop' + Write-Error -Message ( + "Could not resolve the optional dependencies defined for {0}" -f $Type + ) -ErrorAction 'Stop' } switch ($Type) { "VMware" { @@ -146,7 +153,10 @@ function Connect-To { catch { $MessageParams = @{ - Message = "Unable to look up credential store item for RemoteHost {0}/Identifier {1}!" -f $RemoteHost, $Identifier + Message = ( + "Unable to look up credential store item for RemoteHost " + + ("{0}/Identifier {1}!" -f $RemoteHost, $Identifier) + ) ErrorAction = 'Stop' } Write-Error @MessageParams @@ -198,7 +208,10 @@ function Connect-To { if (!($WinSCPSession.Opened)) { # Check the connection state and find out if the session is still open. $MessageParams = @{ - Message = "Connection to {0} using Type {1} was established. But now it seems to be lost!" -f $RemoteHost, $Type + Message = ( + ("Connection to {0} using Type {1} " -f $RemoteHost, $Type) + + "was established. But now it seems to be lost!" + ) ErrorAction = 'Stop' } Write-Error @MessageParams @@ -261,6 +274,8 @@ function Connect-To { ErrorAction = 'Stop' } $Global:PSExchangeRemote = New-PSSession @ConnectionParams + # ScriptAnalyzer issue (unused var) workaround. + $null = $Global:PSExchangeRemote } catch { # Write a error message to the log. @@ -300,7 +315,9 @@ function Connect-To { try { $SessionOption = New-WinSCPSessionOption @WinSCPSessionParams $Global:WinSCPSession = New-WinSCPSession -SessionOption $SessionOption - Write-Verbose -Message ("SCP Connection established with {0}" -f $Global:WinSCPSession.Hostname) + Write-Verbose -Message ( + "SCP Connection established with {0}" -f $Global:WinSCPSession.Hostname + ) } catch { # Write a error message to the log. @@ -314,7 +331,10 @@ function Connect-To { if (!($WinSCPSession.Opened)) { # Check the connection state and find out if the session is still open. $MessageParams = @{ - Message = "Connection to {0} using Type {1} was established. But now it seems to be lost!" -f $RemoteHost, $Type + Message = ( + ("Connection to {0} using Type {1} was established. " -f $RemoteHost, $Type) + + "But now it seems to be lost!" + ) ErrorAction = 'Stop' } Write-Error @MessageParams diff --git a/src/Connection/Disconnect-From.ps1 b/src/Connection/Disconnect-From.ps1 index 509ef4b..a78ae1f 100644 --- a/src/Connection/Disconnect-From.ps1 +++ b/src/Connection/Disconnect-From.ps1 @@ -52,6 +52,11 @@ function Disconnect-From { #> [CmdletBinding()] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSAvoidGlobalVars', + '', + Justification = 'Wrapping existing global vars from external modules' + )] param ( [Parameter(Mandatory = $true)] [string]$RemoteHost, @@ -133,7 +138,9 @@ function Disconnect-From { "NetAppFAS" { try { $MessageParams = @{ - Message = "Setting {0} to `$null, which will disconnect NetAppFAS" -f $Global:CurrentNcController + Message = ( + "Setting {0} to `$null, which will disconnect NetAppFAS" -f $Global:CurrentNcController + ) ErrorAction = 'Continue' } Write-Verbose @MessageParams diff --git a/src/Item/Remove-CredentialStoreItem.ps1 b/src/Item/Remove-CredentialStoreItem.ps1 index 253d501..30552da 100644 --- a/src/Item/Remove-CredentialStoreItem.ps1 +++ b/src/Item/Remove-CredentialStoreItem.ps1 @@ -40,6 +40,11 @@ function Remove-CredentialStoreItem { #> [CmdletBinding(DefaultParameterSetName = 'Private')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute( + 'PSUseShouldProcessForStateChangingFunctions', + '', + Justification = 'Removes data from existing store.' + )] param ( [Parameter(Mandatory = $true, ParameterSetName = 'Private')] [Parameter(Mandatory = $true, ParameterSetName = 'Shared')] @@ -90,7 +95,7 @@ function Remove-CredentialStoreItem { $CredentialName = $RemoteHost } - if (Get-Member -InputObject $CSContent -Name $CredentialName -Membertype NoteProperty) { + if (Get-Member -InputObject $CSContent -Name $CredentialName -MemberType NoteProperty) { # We need to use the .NET Method because there is no easier way in PowerShell. $CSContent.PSObject.Properties.Remove($CredentialName) ConvertTo-Json -InputObject $CSContent -Depth 5 | Out-File -FilePath $Path -Encoding utf8 diff --git a/src/Private/Get-DefaultCredentialStorePath.ps1 b/src/Private/Get-DefaultCredentialStorePath.ps1 index f235ce3..d0cb576 100644 --- a/src/Private/Get-DefaultCredentialStorePath.ps1 +++ b/src/Private/Get-DefaultCredentialStorePath.ps1 @@ -33,7 +33,11 @@ function Get-DefaultCredentialStorePath { if ($IsMacOS) { return Join-Path -Path '/var/opt' -ChildPath 'PSCredentialStore/CredentialStore.json' } - elseif (($isWindows) -or ($PSVersionTable.PSVersion.Major -lt 6) -or ($PSVersionTable.PSEdition -eq 'Desktop')) { + elseif ( + ($isWindows) -or + ($PSVersionTable.PSVersion.Major -lt 6) -or + ($PSVersionTable.PSEdition -eq 'Desktop') + ) { return Join-Path -Path $env:ProgramData -ChildPath 'PSCredentialStore/CredentialStore.json' } } @@ -44,7 +48,11 @@ function Get-DefaultCredentialStorePath { if ($IsMacOS) { return Join-Path -Path $Env:HOME -ChildPath 'CredentialStore.json' } - elseif (($isWindows) -or ($PSVersionTable.PSVersion.Major -lt 6) -or ($PSVersionTable.PSEdition -eq 'Desktop')) { + elseif ( + ($isWindows) -or + ($PSVersionTable.PSVersion.Major -lt 6) -or + ($PSVersionTable.PSEdition -eq 'Desktop') + ) { return Join-Path -Path $env:AppData -ChildPath 'CredentialStore.json' } } diff --git a/src/Private/Import-CSPfxCertificate.ps1 b/src/Private/Import-CSPfxCertificate.ps1 index f1decc3..3b59dc2 100644 --- a/src/Private/Import-CSPfxCertificate.ps1 +++ b/src/Private/Import-CSPfxCertificate.ps1 @@ -5,8 +5,8 @@ function Import-CSPfxCertificate { .DESCRIPTION This function is used to import existing pfx certificate files. The Import-PFXCertificate cmdlet from the - PKI module imports the certificate into a deprecated store. Thus you can't read the private key afterwards or - using it for decrypting data. + PKI module imports the certificate into a deprecated store. Thus you can't read the private key afterwards + or using it for decrypting data. .PARAMETER Path Path to an existing *.pfx certificate file. @@ -83,7 +83,9 @@ function Import-CSPfxCertificate { ) if (Test-CSPfxCertificate -Thumbprint $cert.Thumbprint) { - Write-Warning -Message ('The certificate with thumbprint {0} is already present!' -f $cert.Thumbprint) + Write-Warning -Message ( + 'The certificate with thumbprint {0} is already present!' -f $cert.Thumbprint + ) } else { $Store.Add($cert) diff --git a/src/Private/Resolve-Dependency.ps1 b/src/Private/Resolve-Dependency.ps1 index 8b7cc77..9f99a69 100644 --- a/src/Private/Resolve-Dependency.ps1 +++ b/src/Private/Resolve-Dependency.ps1 @@ -36,7 +36,9 @@ function Resolve-Dependency { .EXAMPLE If (-not (Resolve-Dependency -Name 'VMware')) { - Write-Error -Message ("Could not resolve the optional dependencies defined for {0}" -f 'VMware') -ErrorAction 'Stop' + Write-Error -Message ( + "Could not resolve the optional dependencies defined for {0}" -f 'VMware' + ) -ErrorAction 'Stop' } #> @@ -60,6 +62,8 @@ function Resolve-Dependency { } process { + # ScriptAnalyzer issue workaround (unused var) + $null = $Name $SelectedDependency = $Dependency.Optional | Where-Object { $_.Name -match $Name } # return true if there is no dependency defined if ($null -eq $SelectedDependency) { diff --git a/src/Private/Test-CSPfxCertificate.ps1 b/src/Private/Test-CSPfxCertificate.ps1 index 64c427b..b37d4cd 100644 --- a/src/Private/Test-CSPfxCertificate.ps1 +++ b/src/Private/Test-CSPfxCertificate.ps1 @@ -64,6 +64,8 @@ function Test-CSPfxCertificate { } process { + # Script analyzer issue (unused var) workaround + $null = $Thumbprint $Cert = $Store.Certificates | Where-Object { $_.Thumbprint -eq $Thumbprint } if ($null -eq $Cert) {