To force an Azure Pipeline task to use PowerShell Core (specifically PowerShell 7+), you can specify the pwsh command in your pipeline YAML. This ensures that the task runs in the context of PowerShell Core instead of Windows PowerShell.
Here’s how you can do it:
Example YAML Pipeline
yaml
Copier
jobs:
- job: PowerShellCoreJob
pool:
vmImage: 'windows-latest'
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
# Your PowerShell Core script goes here
Write-Host "Running in PowerShell Core"
pwsh: true # This explicitly tells the task to use PowerShell Core
Key Points
Task Type: Use the PowerShell@2 task.
pwsh: true: This input parameter tells the task to use PowerShell Core.
Inline or File: You can provide an inline script or reference a script file.
Additional Configuration
If you're using a script file instead of inline code, make sure to provide the path to the script and still set pwsh: true:
yaml
Copier
steps:
- task: PowerShell@2
inputs:
targetType: 'filePath'
filePath: 'path/to/your/script.ps1'
pwsh: true
By specifying pwsh: true, your scripts will run using PowerShell Core, allowing you to leverage the features and enhancements of the newer version.