private/get/Get-SessionManagerPluginFilePath.ps1
function Get-SessionManagerPluginFilePath { [CmdletBinding(PositionalBinding = $true)] [OutputType([string])] param() $downloadFolder = New-Item -Force -ItemType Directory -Path "$env:TEMP" -Name 'EC2Remote' $executablePath = Join-Path -Path $downloadFolder -ChildPath 'session-manager-plugin.exe' if (Test-Path -Path $executablePath) { return $executablePath } $rootArchive = Join-Path -Path $downloadFolder -ChildPath 'SessionManagerPlugin.zip' $rootExpandPath = Join-Path -Path $downloadFolder -ChildPath 'SessionManagerPlugin' $childArchive = Join-Path -Path $rootExpandPath -ChildPath 'package.zip' $childExpandPath = Join-Path -Path $rootExpandPath -ChildPath 'package' $exePath = Join-Path -Path $childExpandPath -ChildPath 'bin\session-manager-plugin.exe' Write-Host 'Downloading latest AWS Session Manager Plugin.. ' -ForegroundColor DarkGray -NoNewline $params = @{ Uri = 'https://s3.amazonaws.com/session-manager-downloads/plugin/latest/windows/SessionManagerPlugin.zip' OutFile = $rootArchive } Invoke-WebRequest @params Write-Host 'Done.' -ForegroundColor Green Expand-Archive -Force -Path $rootArchive -DestinationPath $rootExpandPath Expand-Archive -Force -Path $childArchive -DestinationPath $childExpandPath Move-Item -Force -Path $exePath -Destination $executablePath Remove-Item -Path $rootArchive Remove-Item -Path $rootExpandPath -Recurse return $executablePath } |