When running "Powershell on Remote Machine" task in Azure Devops (on-premise) server, we consistently see a 30 second pause in the execution.
This makes even very simple remote remote script invocations take at least 30 seconds to complete.
Changing the task to a normal powershell task and setting up the PSSession manually and issuing the exact same Invoke-Command runs much faster.
So question is, is this a bug in Azure Devops server, or is there some additional configuration that we need to do for the Powershell on remote machine tasks, to make it perform better? We have not tried to tweak anything - just used the default task configurations.
Azure Devops server version is 2019 Update 1. Agents are updated to latest version.
Output from "Powershell on remote machine" Azure Devops task:
2019-10-10T04:51:03.4296728Z ##[section]Starting: <hidden> - Stop site
2019-10-10T04:51:03.4727773Z ==============================================================================
2019-10-10T04:51:03.4728808Z Task : PowerShell on target machines
2019-10-10T04:51:03.4728850Z Description : Execute PowerShell scripts on remote machines using PSSession and Invoke-Command for remoting
2019-10-10T04:51:03.4728886Z Version : 3.1.2
2019-10-10T04:51:03.4728935Z Author : Microsoft Corporation
2019-10-10T04:51:03.4728970Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/deploy/powershell-on-target-machines
2019-10-10T04:51:03.4729006Z ==============================================================================
2019-10-10T04:51:08.6710628Z PSSession created for Machines:'<hidden>'
2019-10-10T04:51:08.9207041Z ================================================ <hidden> ================================================
2019-10-10T04:51:38.9317626Z ================================================ <hidden> ================================================
2019-10-10T04:51:38.9325165Z ##[command]& 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'C:\Users\<hidden>\AppData\Local\Temp\f228e8e1-f90a-4263-89cd-55320f5ad80b.ps1'"
2019-10-10T04:51:38.9630832Z
2019-10-10T04:51:39.0526046Z Script execution succeeded for ComputerName: '<hidden>'
2019-10-10T04:51:39.3236823Z ##[section]Finishing: <hidden> - Stop site
OBS the 30 second pause from 2019-10-10T04:51:08.9207041Z to 2019-10-10T04:51:38.9317626Z. We see this kind of pause in all our Powershell to target machine tasks.
Changing to a normal Powershell task and setting up the PSSession manually, will make the script run much faster. We implement it like this:
$password = ConvertTo-SecureString "$(PASSWORD)" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("$(USER)", $password)
$session = New-PSSession -ComputerName $(SERVER) -Credential $cred -UseSSL
Invoke-Command -Session $session -ScriptBlock { `
Copy-Item "C:\Users\<HIDDEN>\Documents\app_offline.htm" `
"$(DEPLOY_PATH)\app_offline.htm" `
}