简体   繁体   English

如何通过 AWS 工具使用来自 AzureDevops 的 Powershell 7

[英]How to use Powershell 7 from AzureDevops with AWS Tools

I am writing a powershell script and would like to take advantage of the 7.0 version of Powershell.我正在编写 powershell 脚本,并希望利用 Powershell 的 7.0 版本。 Specifically because I need access to the new features of CovertFrom-Json that are not available in 5.1.特别是因为我需要访问 5.1 中没有的 CovertFrom-Json 的新功能。 My script has the following command: get-host | select version我的脚本有以下命令: get-host | select version get-host | select version . get-host | select version The log output shows the version is 5.1.日志 output 显示版本为 5.1。 The Agent is a windows-2019 (2020 isn't available in the drop down).代理是 windows-2019(2020 在下拉菜单中不可用)。 The task is a AWS Tools for Windows PowerShell Script task.该任务是用于 Windows PowerShell 脚本任务的 AWS 工具 Is there a way I can get my script to run in an environment on DevOps to make use of PS 7?有没有办法让我的脚本在 DevOps 的环境中运行以利用 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: powershell任务为您提供:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      17763  1852    

but pwsh :但是pwsh

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      1      3  

But AWS Tools for Windows PowerShell Script doesn't support Powershell Core.但是AWS Tools for Windows PowerShell Script不支持 Powershell 核心。 And looking at this that there is no way to replace powershell with pwsh making the second a default shell.看看这个,没有办法用 pwsh 替换 powershell,使第二个成为默认 shell。 In this case I would recommend to create a feature request for AWS Tools for Windows PowerShell Script在这种情况下,我建议AWS Tools for Windows PowerShell Script的功能请求

However, you can still install AWS Toolkit and use it from pwsh task as follows:但是,您仍然可以安装 AWS Toolkit 并从 pwsh 任务中使用它,如下所示:

- pwsh: Install-Module -name AWSPowerShell.NetCore -Scope CurrentUser -Force
- pwsh: |
    Import-Module AWSPowerShell.NetCore
    Get-Module -ListAvailable

    Get-AWSPowerShellVersion

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM