You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When both ShowWarnings is enabled, the value of $VerbosePreference is a string and not a proper enum value.
A common powershell pattern is to call a function with -Verbose:$VerbosePreference to prevent verbosity from disappearing as we cross a barrier into another script or function.
Because of this combination, the following error is produced:
System.Management.Automation.ParameterBindingException: Cannot convert 'System.String' to the
type 'System.Management.Automation.SwitchParameter' required by parameter 'Verbose'.
This normally works because Powershell silently converts the [Management.Automation.ActionPreference] into a [SwitchParameter] or something like it.
New issue checklist
Task name
Powershell@2
Task version
2.230.0
Issue Description
When both
ShowWarnings
is enabled, the value of$VerbosePreference
is a string and not a proper enum value.A common powershell pattern is to call a function with
-Verbose:$VerbosePreference
to prevent verbosity from disappearing as we cross a barrier into another script or function.Because of this combination, the following error is produced:
This normally works because Powershell silently converts the
[Management.Automation.ActionPreference]
into a[SwitchParameter]
or something like it.So, this works:
yielding the verbose message
Unfortunately, when
ShowWarnings
is enabled, the inline script is run inside of an invoke-command.And in this case the auto-conversion fails.
So,
yields
Environment type (Please select at least one enviroment where you face this issue)
Azure DevOps Server type
Azure DevOps Server (Please specify exact version in the textbox below)
Azure DevOps Server Version (if applicable)
Version Azure DevOps Server 2022.0.1 (AzureDevOpsServer_20231109.3)
Operation system
Windows 10
Relevant log output
Full task logs with system.debug enabled
Repro steps
aside: since the log does not include it, our build server has PS version 5.1.17763.6640
Task config in pipeline:
The text was updated successfully, but these errors were encountered: