XCP-ng Installing citrix agent for windows via powershell script

I have a nifty little script to run if you don’t want to bother with citrix’s workaround to download the agent from their site. As always I encourage everyone to review any script they pull off the internet for malicious acts. The script should be easily readable. Copy the script from below and save it as a ps1 file or copy and paste it into a powershell ISE session ran as administrator. Enjoy!

Write-Verbose "Loading Functions" -Verbose

function get-latestVersion {
    $uri = "https://pvupdates.vmd.citrix.com/updates.latest.tsv"
    $results = @()
    $temp = New-TemporaryFile
    wget $uri -OutFile $temp
    $raw = get-content $temp
    foreach ($line in $raw) 
    {
        $parts = $line.split("`t")
        $result = @{ 
            "URL"=$parts[0];
            "Version"=[version]$parts[1];
            "Size"=$parts[2];
            "Architecture"=$parts[3]
        }
        $results += $result
    }
    Write-Output $results
}

Write-Verbose "Setting Arguments" -Verbose
$StartDTM = (Get-Date)

$Vendor = "Citrix"
$Product = "XenServer"
$PackageName = "managementagentx64"
$Latest = get-latestVersion | ? architecture -eq "x64"
$Version = $Latest.version
$InstallerType = "msi"
$Source = "$PackageName" + "." + "$InstallerType"
$LogPS = "C:\Windows\Temp\$Vendor $Product $Version PS Wrapper.log"
$LogApp = "C:\Windows\Temp\XS65FP1.log"
$UnattendedArgs = "/i $PackageName.$InstallerType ALLUSERS=1 /Lv $LogApp /quiet /norestart"
$URL = $Latest.url

Start-Transcript $LogPS

if( -Not (Test-Path -Path $Version ) )
{
    New-Item -ItemType directory -Path $Version
}

CD $Version

Write-Verbose "Downloading $Vendor $Product $Version" -Verbose
If (!(Test-Path -Path $Source)) {
    Invoke-WebRequest -Uri $url -OutFile $Source
         }
        Else {
            Write-Verbose "File exists. Skipping Download." -Verbose
         }

Write-Verbose "Starting Installation of $Vendor $Product $Version" -Verbose
(Start-Process msiexec.exe -ArgumentList $UnattendedArgs -Wait -Passthru).ExitCode

Write-Verbose "Customization" -Verbose

Write-Verbose "Stop logging" -Verbose
$EndDTM = (Get-Date)
Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalSeconds) Seconds" -Verbose
Write-Verbose "Elapsed Time: $(($EndDTM-$StartDTM).TotalMinutes) Minutes" -Verbose
Stop-Transcript
1 Like

I’ll give this a try when I have a chance, thanks. Will this update as well as install from a fresh install?

I believe the agent updates on its own when installed. So no need to run this script for upgrades.

The script pulls an old location, it only grabs version 7.2.x and Citrix is up to 9.3. When I open the .tsv that it pulls, this is the text:

http://downloadns.citrix.com.edgesuite.net/14645/managementagentx86.msi 7.2.0.1537 9859072 x86 0 736b42e6744433f047a74bba4e1e9ef2bc9083ba59344063ee9b25bc4448aa55
http://downloadns.citrix.com.edgesuite.net/14644/managementagentx64.msi 7.2.0.1537 9871360 x64 0 69569cdf9187ef9dfe5ec443e00ae46de944d349560645e3d2ec5f474b7b0239

Not sure why they would limit that update URL to an old version.

Yeah I have no idea. It eventually updates the agent automatically to the latest version. Why they don’t get the latest agent right out of the gate? Because its citrix and they probably haven’t updated that site in a while.

Could this fix the script to pull the latest version? They are now pulling a JSON file to lead back to the versions: How does Management Agent auto update work

About mid page they discuss the difference.

[edit] nope, still pulling the 7.2 version