Partager via


PowerShell@1 - PowerShell v1 task

Run a PowerShell script.

Inputs

scriptType - Type
string. Required. Allowed values: inlineScript (Inline Script), filePath (File Path). Default value: filePath.

Specifies the type of script for the task to run: an inline script or a path to a .ps1 file.


scriptName - Script Path
string. Required when scriptType = filePath.

Specifies the type of script for the task to run: an inline script or a path to a .ps1 file.


arguments - Arguments
string.

Specifies the arguments passed to the PowerShell script. Arguments can be ordinal parameters or named parameters. For example, -Name someName -Path -Value "Some long string value".

arguments is not used when targetType is set to inline.


workingFolder - Working folder
string.

Specifies the working directory where the script is run. If a value is not specified, the working directory is $(Build.SourcesDirectory).


inlineScript - Inline Script
string. Required when scriptType = inlineScript. Default value: # You can write your powershell scripts inline here. \n# You can also pass predefined and custom variables to this scripts using arguments\n\n Write-Host "Hello World".

Specifies the contents of the script. The maximum supported inline script length is 500 characters. Use a script from a file if you want to use a longer script.


failOnStandardError - Fail on Standard Error
boolean. Default value: true.

If the value of this boolean is true, the task fails if any errors are written to the error pipeline or if any data is written to the Standard Error stream. Otherwise, the task relies on the exit code to determine failure.


Task control options

All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.

Output variables

None.

Remarks

PowerShell@1 runs only on Windows agents. To run PowerShell on other agent types, use PowerShell@2.

Each PowerShell session lasts only for the duration of the job in which it runs. Tasks that depend on what has been bootstrapped must be in the same job as the bootstrap.

Set a variable so it can be read by subsequent scripts and tasks

To learn more about defining build variables in a script, see Define and modify your build variables in a script.

To learn more about defining release variables in a script, see Define and modify your release variables in a script.

Passing pipeline secrets in script, but secret is not masked in pipeline logs

Be aware that PowerShell cuts off error messages, so if you use pipeline secrets in a script, the secrets could be trimmed and exposed. For example, in the inline script below:

./script.ps1 --arg1 value1 --arg2 <some_secret_which_will_be_masked_here>

There could be an exception like: At <path_to_temp_script_file>:4 char:3:

+   ./script.ps1 --arg1 value1 --arg2 <unmasked_part_of_original_secret> ...
+   ~~~~~~~~~~
    + <Additional exception details>

To avoid this issue, you can handle these exceptions on a script level, or avoid cases when pipeline secrets could appear in source code lines within error messages.

Requirements

Requirement Description
Pipeline types YAML, Classic build, Classic release
Runs on Agent, DeploymentGroup
Demands Self-hosted agents must have capabilities that match the following demands to run jobs that use this task: DotNetFramework
Capabilities This task does not satisfy any demands for subsequent tasks in the job.
Command restrictions Any
Settable variables Any
Agent version 1.102 or greater
Task category Utility

See also