From c7097c4403312e162a018914f33625df9f6d54a2 Mon Sep 17 00:00:00 2001
From: Sean Millichamp <sean.millichamp@global.ntt>
Date: Tue, 13 Aug 2024 14:36:10 -0400
Subject: [PATCH] Save Windows Powershell agent installer to Task temp dir

Without an explicit destination path specified, the download
of install.ps1 is being written to the Windows system directory.

This adjusts the Task to obtain the path it is located in and
save the install.ps1 download there.
---
 tasks/agent_install.ps1 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tasks/agent_install.ps1 b/tasks/agent_install.ps1
index fcc8456e..33e00c1a 100644
--- a/tasks/agent_install.ps1
+++ b/tasks/agent_install.ps1
@@ -8,8 +8,9 @@ if (Test-Path "C:\Program Files\Puppet Labs\Puppet\puppet\bin\puppet"){
   Exit 1
 }
 $flags=$install_flags -replace '^\["*','' -replace 's/"*\]$','' -replace '/", *"',' '
+$mypath = $MyInvocation.MyCommand.Path | Split-Path -Parent
 try {
-  [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = New-Object System.Net.WebClient; $webClient.DownloadFile("https://${server}:8140/packages/current/install.ps1", 'install.ps1'); powershell.exe -c "install.ps1 $flags"
+  [Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}; $webClient = New-Object System.Net.WebClient; $webClient.DownloadFile("https://${server}:8140/packages/current/install.ps1", "${mypath}\install.ps1"); powershell.exe -c "${mypath}\install.ps1 $flags"
   }
   catch {
   Write-Host "Installer failed with Exception: $_.Exception.Message"