Snippets

Avantra Dev Team Install Avantra Agent via PowerShell Remoting

Created by Heiko Mannherz last modified
# - Upload the Avantra Agent installer as a package to the Agent Update rpository
# - Adapt these variable according to your needs
# - Modify the execution policy to allow running powershell scripts
[string]$user = '<DOMAIN\user>'          # Access to the remote system
[string]$target = '<target-host>'        # The remote system
[string]$masterhost = '<avantra-server>' # The FQDN of the Avantra Sever
[string]$agentversion = '20.5.0'         # The agent version (uploaded to the repository)
[string]$javapath = 'C:\Program Files\Java'
# Adapt this to the latest version: Make your choice on https://adoptopenjdk.net/releases.html, right-click to get link
[uri]$javaurl = 'https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u252-b09.1/OpenJDK8U-jre_x64_windows_hotspot_8u252b09.msi'

# There should be no need to change anything below this line

[uri]$agenturl = 'http://' + $masterhost + ':9050/AgentUpdate/agent-' + $agentversion + '-setup.exe'

# Self-elevate the script if required
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
    if ([int](Get-CimInstance -Class Win32_OperatingSystem | Select-Object -ExpandProperty BuildNumber) -ge 6000) {
        $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
        Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine
    Exit
    }
}

$session = New-PSSession -ComputerName $target -Credential $user

Invoke-Command -Session $session -ScriptBlock {
    param($javaurl, $agenturl, $javapath)
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    Invoke-WebRequest `
        -Uri $javaurl `
        -OutFile 'C:\Windows\Temp\java-installer.msi'
    Invoke-WebRequest `
        -Uri $agenturl `
        -OutFile 'C:\Windows\Temp\agent-installer.exe'
    msiexec /i C:\Windows\Temp\java-installer.msi /quiet `
        ADDLOCAL="FeatureMain,FeatureEnvironment,FeatureJarFileRunWith,FeatureJavaHome,FeatureOracleJavaSoft" `
        INSTALLDIR=`"$javapath`"
    C:\Windows\Temp\agent-installer.exe /S /JAVA_PATH=`"$javapath`" /START_SERVICE=1 /PORT=9051 /D=C:\Program Files\avantra
} -ArgumentList $javaurl,$agenturl,$javapath
    Remove-Item -path 'C:\Windows\Temp\java-installer.msi'
    Remove-Item -path 'C:\Windows\Temp\agent-installer.exe'
Remove-PSSession $session 

Comments (1)

  1. Heiko Mannherz Account Deactivated

    There are a few things to consider:

    • You need to have enabled PowerShell Remoting. This is probably easiest in an Active Directory environment. If you don’t have enabled it, it is likely the setup of PowerShell Remoting takes more time than installing the Avantra Agents everywhere.
    • You need to set the Execution Policy on the computer you intend to run the script appropriately: Check if your security policies allow such a change. You may consider the value RemoteSigned.

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.