Closed
Description
Consider the following function,
function do-whatever
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingUserNameAndPassWordParams', 'Username')]
param(
[string] $Username,
[string] $Password
)
}
Invoking script analyzer on the a file containing the above defined function causes script analyzer to throw the following error message.
PS>Invoke-ScriptAnalyzer -Path ~\tmp\test1.ps1 -Verbose -IncludeRule PSAvoidUsingUserNameAndPassWordParams
VERBOSE: Analyzing file: C:\Users\kabawany\tmp\test1.ps1
VERBOSE: Running PSAvoidUsingUserNameAndPassWordParams rule.
Invoke-ScriptAnalyzer : The WriteObject and WriteError methods cannot be called from outside the overrides of the BeginProcessing, ProcessRecord, and EndProcessing methods, and they can
only be called from within the same thread. Validate that the cmdlet makes these calls correctly, or contact Microsoft Customer Support Services.
At line:1 char:1
+ Invoke-ScriptAnalyzer -Path ~\tmp\test1.ps1 -Verbose -IncludeRule PSA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (C:\Users\kabawany\tmp\test1.ps1:String) [Invoke-ScriptAnalyzer], PSInvalidOperationException
+ FullyQualifiedErrorId : RULE_ERROR,Microsoft.Windows.PowerShell.ScriptAnalyzer.Commands.InvokeScriptAnalyzerCommand