While working on the Automation Framework 3.8 release I needed to put the Framework ZIP on a diet. Over the years it’s been growing above 1 GB so it was about time to add even more functions to automatically download source files from the internet.
During my research for the post Windows Module Installer High CPU on Citrix XenServer I stumbled upon this Citrix article How does Management Agent auto-update work.
Now the Citrix Auto Update agent only works if you’re licensed, but what if we could use that updates.latest.tsv file to automatically download and install the latest Citrix XenServer tools?
That’s what you’ll get below in today’s quick post. Many thanks to my PowerShell mentor Bronson Magnan for always helping out when I’m stuck.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
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 |
That’s it – a neat script to install the latest Citrix XenServer tools!