PSScriptAnalyzer rule

This topic contains 1 reply, has 1 voice, and was last updated by  John Steele 1 month ago.

  • Author
    Posts
  • #100858

    John Steele
    Participant

    I've written a module that uses this little bit of code

    $keyValues = @()
    $sigParams.GetEnumerator() | Sort-Object Name | ForEach-Object {
        $keyValues += "$($_.Key)$($_.Value)"
        Write-Verbose "$keyValues"
    }
    
    $string = $keyValues -join ''
    

    Even though I use $keyValues to create the $string variable PSScriptAnalyzer freaks out and tells me $keyValues is not being used. The only way I've figured out to quiet the rule was to add the 'Write-Verbose "$keyValues"' line.

    Is there a better way to code this or should I just ignore PSScriptAnalyzer in this case and move on?

  • #100863

    John Steele
    Participant

    Walking away for a couple hours helped. This is what I ended up coming up with. It keeps PSScriptAnalyzer happy and I think it looks cleaner too, so win win.

    $keyValues = $sigParams.GetEnumerator() | Sort-Object Name | ForEach-Object {
        "$($_.Key)$($_.Value)"
    }
    
    $string = $keyValues -join ''
    

You must be logged in to reply to this topic.