Skip to content

PSScriptAnalyzer marks unused param but it is used in the script #1924

Closed
@ktran1005

Description

@ktran1005

Before submitting a bug report:

  • Make sure you are able to repro it on the latest released version
  • Perform a quick search for existing issues to check if this bug has already been reported

Steps to reproduce
Hello everyone, I am a newbie to PSScriptAnalyzer. I run into a little issue. I run PSScriptAnalyzer to one of my script and here is the warning I received "The parameter "ipAddress" has been declared but not used". I wonder that can this warning consider as false positive since my script did use this parameter by passing it to another script. Any response would be appreciated!

param(
        [Parameter(Mandatory)] [string]$acrName,
        [Parameter(Mandatory)] [string]$ipAddress
)

$networkRuleExists = $false
$existingNetworkRules = ./Get-AcrNetworkRule -acrName $acrName
$existingNetworkRules.ipRules | ForEach-Object -Process { 
    if($_.ipAddressOrRange -eq $ipAddress){ 
        Write-Output "NetworkRule already exists."; 
        $networkRuleExists = $true;
        if(!$networkRuleExists)
            {
                az acr network-rule add --name $acrName --ip-address $ipAddress
                if($LASTEXITCODE -ne 0){Throw "az acr network-rule add returned a $LASTEXITCODE exit code."}
                Start-Sleep -Seconds 120
            } 
        return 
    } 

}

Expected behavior

expected none

Actual behavior

 The parameter 'ipAddress' has been declared but not used.

If an unexpected error was thrown then please report the full error details using e.g. $error[0] | Select-Object *

Environment data

> $PSVersionTable

> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions