I am writing a powershell script and would like to take advantage of the 7.0 version of Powershell. Specifically because I need access to the new features of CovertFrom-Json that are not available in 5.1. My script has the following command: get-host | select version
get-host | select version
. The log output shows the version is 5.1. The Agent is a windows-2019 (2020 isn't available in the drop down). The task is a AWS Tools for Windows PowerShell Script task. Is there a way I can get my script to run in an environment on DevOps to make use of PS 7?
You have it already installed there. Please compare this:
pool:
vmImage: windows-latest
steps:
- powershell: $PSVersionTable.PSVersion
- pwsh: $PSVersionTable.PSVersion
- pwsh: |
'{ "key":"value1", "Key":"value2" }' | ConvertFrom-Json -AsHashtable
powershell
task gives you:
Major Minor Build Revision
----- ----- ----- --------
5 1 17763 1852
but pwsh
:
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
7 1 3
But AWS Tools for Windows PowerShell Script
doesn't support Powershell Core. And looking at this that there is no way to replace powershell with pwsh making the second a default shell. In this case I would recommend to create a feature request for AWS Tools for Windows PowerShell Script
However, you can still install AWS Toolkit and use it from pwsh task as follows:
- pwsh: Install-Module -name AWSPowerShell.NetCore -Scope CurrentUser -Force
- pwsh: |
Import-Module AWSPowerShell.NetCore
Get-Module -ListAvailable
Get-AWSPowerShellVersion
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.