如何将PowerShell脚本中的文件复制到带有管道代理的部署组中带有DevOps发布管道的部署组中的多个目标计算机

时间:2020-07-24 01:18:00

标签: powershell devops powershell-3.0 azure-pipelines-release-pipeline

我有一个DevOps发布管道,该管道可以部署到部署组中的目标。只有一个目标时,一切工作正常。现在,我添加了另一个目标,执行了大约7个步骤后,最后一步失败了。这是Powershell脚本

Clear-Host;

# wait 3 minutes
Start-Sleep 180;

# Archive Current Install Files
$date=$(Get-Date -Format "MMddyyyy");
$archiveDir="C:\...\Archives\$($date)";
$archiveDirectoryExists=Test-Path -Path $archiveDir;

if(!$archiveDirectoryExists){
    New-Item -ItemType directory -Path $archiveDir;
}
Write-Host "Copying Temp\mmddyyyy to C:\...\Archives\mmddyyyy -->";
Copy-Item "C:\Temp\$($date)\*" -Destination "$($archiveDir)" -Recurse;

#Copy the Log Files
$passServerLogFile="C:\ProgramData\...log";
$passServerLogFileExists=Test-Path -Path $passServerLogFile;
if($passServerLogFileExists){
    Write-Host "Copying PASSServer.log-->";
    Copy-Item $passServerLogFile -Destination "$($archiveDir)\";
}

$passWareClientLogFile="C:\ProgramData\....log";
$passWareClientLogFileExists=Test-Path -Path $passWareClientLogFile;
if($passWareClientLogFileExists){
    Write-Host "Copying PASSWare Client.log-->";
    Copy-Item $passWareClientLogFile -Destination "$($archiveDir)\";
}

#Copy the .Config file
$passServerConfigFile="C:\ProgramData\....Config"
$passServerConfigFileExists=Test-Path -Path $passServerConfigFile;
if($passServerConfigFileExists){
    Write-Host "Copying PASSServer.exe.Config-->";
    Copy-Item $passServerConfigFile -Destination "$($archiveDir)\"
}

Start-Sleep 30;

#delete the Temp\rollback directory
$tempRollbackDir="C:\Temp\rollback";
Remove-Item "$($tempRollbackDir)\*" -Force -Recurse;

Start-Sleep 30;

#delete the Temp\MMDDYYYY directory
$tempDir="C:\Temp\$($date)";
Remove-Item "$($tempDir)" -Force -Recurse;

这是错误...

2020-07-23T20:47:58.8049592Z ##[section]Starting: Archive Current Install Files & Log Files --> C:\Parata\PASSWareClient\Archives\MMDDYYYY
2020-07-23T20:47:58.8365217Z ==============================================================================
2020-07-23T20:47:58.8365529Z Task         : PowerShell
2020-07-23T20:47:58.8365805Z Description  : Run a PowerShell script on Linux, macOS, or Windows
2020-07-23T20:47:58.8366049Z Version      : 2.170.1
2020-07-23T20:47:58.8366246Z Author       : Microsoft Corporation
2020-07-23T20:47:58.8366554Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
2020-07-23T20:47:58.8366925Z ==============================================================================
2020-07-23T20:48:00.5803918Z Generating script.
2020-07-23T20:48:00.6639093Z ========================== Starting Command Output ===========================
2020-07-23T20:48:00.6878207Z ##[command]"C:\windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\azagent\A2\_work\_temp\0c449656-040a-4e51-bba5-0899168abff4.ps1'"
2020-07-23T20:48:00.7994212Z I

该错误没有意义,因为它只能在一台计算机上运行,​​而不能在另一台计算机上运行。另外,它如何提及-ExecutionPolicy Unrestricted,这对我来说是不可思议的。为什么在这台特定的机器上对此有什么说法呢?你们可以帮忙吗?

0 个答案:

没有答案