From babd33d2cdfe05abb6da837b5b175f5ebcbeb3ff Mon Sep 17 00:00:00 2001 From: ScriptAutomate Date: Tue, 26 Sep 2023 13:38:56 -0500 Subject: [PATCH] Add logging to download-ec2-pubkey script --- os-images/AWS/windows/scripts/InstallAndConfigureOpenSSH.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/os-images/AWS/windows/scripts/InstallAndConfigureOpenSSH.ps1 b/os-images/AWS/windows/scripts/InstallAndConfigureOpenSSH.ps1 index 530cdd04f..41825b420 100644 --- a/os-images/AWS/windows/scripts/InstallAndConfigureOpenSSH.ps1 +++ b/os-images/AWS/windows/scripts/InstallAndConfigureOpenSSH.ps1 @@ -154,6 +154,7 @@ Get-ChildItem $DATA_DIR\ssh_host_*_key -ErrorAction SilentlyContinue | % { $keyDownloadScript = @' $INSTALL_DIR = [io.path]::combine($env:ProgramFiles, 'OpenSSH') $OPENSSH_UTILS_MODULE = [io.path]::combine($INSTALL_DIR, 'OpenSSHUtils.psd1') +$VerbosePreference = 'Continue' Import-Module $OPENSSH_UTILS_MODULE -Force # Download the instance key pair and authorize Administrator logins using it @@ -171,6 +172,7 @@ $token=Invoke-RestMethod -Method PUT -Uri "http://169.254.169.254/latest/api/tok Write-Host "Downloading the current EC2 Instance Public Key from AWS" Invoke-WebRequest "http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key" -Headers @{"X-aws-ec2-metadata-token" = $token} -Outfile $openSSHAuthorizedKeys +Get-Content $openSSHAuthorizedKeys Write-Host "EC2 Instance Public Key Written To $openSSHAuthorizedKeys" # Ensure access control on administrators_authorized_keys meets the requirements @@ -188,7 +190,7 @@ $principal = New-ScheduledTaskPrincipal ` -LogonType ServiceAccount ` -RunLevel Highest $action = New-ScheduledTaskAction -Execute 'Powershell.exe' ` - -Argument "-NoProfile -File ""$DOWNLOAD_KEYS_SCRIPT""" + -Argument "-NoProfile -File ""$DOWNLOAD_KEYS_SCRIPT"" -Verbose > c:\download-ec2-pubkey.log" $trigger = New-ScheduledTaskTrigger -AtStartup Register-ScheduledTask -Action $action ` -Trigger $trigger `