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 = @{ 
        $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
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.