简体   繁体   English

PowerShell 7 从 Azure DevOps 管道远程处理

[英]PowerShell 7 Remoting from Azure DevOps Pipeline

We were using Azure DevOps Pipelines and PowerShell Remoting to execute PS1 scripts:我们使用 Azure DevOps Pipelines 和 PowerShell Remoting 来执行 PS1 脚本:

trigger: none

jobs:
  - job: PSRemoting
    timeoutInMinutes: 5760
    pool:
      name: 'DevOps-Agent2-VM'
    steps:
    - checkout: none

    - task: PowerShellOnTargetMachines@3
      displayName: 'PSRemoting'
      inputs:
        Machines: '$(VM-PublicIP)'
        UserName: '$(VM-UserName)'
        UserPassword: '$(VM-Password)'
        InlineScript: |
          . C:\Scripts\Test-Parallel.ps1

We have added -parallel feature that requires PowerShell 7 and our scripts are failing now:我们添加了-parallel功能,需要 PowerShell 7 并且我们的脚本现在失败了:

2022-11-02T13:37:18.3246154Z ForEach-Object : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ & 'C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoLogo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (ForEach-Object ...med parameters.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 

At C:\Scripts\Test-Parallel.ps1:3 char:10

+ $items | ForEach-Object -Parallel {

+          ~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : MetadataError: (:) [ForEach-Object], ParentContainsErrorRecordExcep 

   tion

    + FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.ForEachObjectCo 

   mmand

 

##[error]Non-Zero exit code: '1' for ComputerName: 'VM1'
##[error]Atleast one remote job failed. Consult logs for more details. ErrorCodes(s): 'RemoteDeployer_NonZeroExitCode'
##[section]Finishing: PSRemoting

Here is Test-Parallel.ps1 :这是Test-Parallel.ps1

$items = 1..100
 
$items | ForEach-Object -Parallel {
  Write-Host "$(Get-Date) | Sleeping for 1 second..."
  Start-Sleep 1
} -ThrottleLimit 10 

How can we force PowerShell to run version 7 with our Azure DevOps Pipeline task?我们如何强制 PowerShell 使用我们的 Azure DevOps 管道任务运行版本 7?

Try this in your Test-Parallel.ps1 script:在您的Test-Parallel.ps1脚本中试试这个:

workflow Test-PipelineDeploy {
  $items = 1..100

  foreach -parallel ($item in $items) {
    Write-Host "$(Get-Date) | Sleeping for 1 second..."
    Start-Sleep 1
  } -ThrottleLimit 10 
}

Then call Test-PipelineDeploy然后调用Test-PipelineDeploy

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

相关问题 Azure DSC 与 PowerShell 7 - Azure DSC with PowerShell 7 PowerShell是否会根据需要自动将管道对象转换为字符串? - Does PowerShell automatically convert pipeline objects to strings as needed? 如何在 Powershell 中检索 Azure 服务主体的秘密 7 - How to retrieve Azure Service Principal's secret in Powershell 7 为什么 Powershell 的 Set-Content -Value 参数不能正确读取管道变量 - Why does Powershell's Set-Content -Value argument not read Pipeline Variable correctly 如何在运行 Linux 的 Azure 应用服务上运行 PowerShell 脚本? - How do I run a PowerShell script on an Azure App Service running Linux? 如何在使用 Terraform (Azure) 创建 Windows VM 资源时运行 Powershell7 脚本 - How do I run a Powershell7 Script upon creation of a Windows VM Resource with Terraform (Azure) Function 从 Powershell 5 移植到 Powershell 7 失败,并显示“对象引用未设置为对象的实例” - Function ported from Powershell 5 to Powershell 7 fails with “object reference not set to an instance of an object” 适用于 PowerShell 7 的 Azure 自动化混合工作者 Get-AutomationPSCredential - Azure Automation Hybrid-Worker Get-AutomationPSCredential for PowerShell 7 无法使用 Windows 10 中的 Powershell 7.1 中的 git - Unable to use git from Powershell 7.1 in Windows 10 如何使用 PowerShell 7 在 Azure 中获取任何 Blob 属性 - How To Get Any Blob Property in Azure using PowerShell 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM