I wrote my first blog post about ControlUp back in 2011. We’ve been in love ever since. Both my blog and ControlUp has grow big since then.
An interesting story is that after my post went live they got hundreds of trail signups the first day. They REALLY understood the power of our community and have been sponsoring every event and blog they can get their hands on ever since.
One thing that has been bothering me for a long time is an evergreen download URL. The main reason for this is the fact that the release cycle is really fast and since I’m using the MSI version there’s no way to upgrade the agent from the console.
This is not big deal for me because of my Citrix XenApp and XenDesktop Rolling Upgrade script, but still I want an evergreen installation script. So as usual I reached out to my PowerShell mentor and he came up with the functions which I added to my install wrapper. Enjoy.
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# https://github.com/BronsonMagnan/SoftwareUpdate/blob/master/ControlUpAgent.ps1 function Get-CurrentControlUpAgentVersion { [cmdletbinding()] [outputType([version])] param() $agentURL = "http://www.controlup.com/products/controlup/agent/" #ControlUP forces TLS 1.2 and rejects TLS 1.1 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $webrequest = wget -Uri $agentURL -UseBasicParsing $content = $webrequest.Content #clean up the code into paragraph blocks $paragraphSections = $content.replace("`n","").replace(" ","").replace("`t","").replace("<p>","#$%^<p>").split("#$%^").trim() #now we are looking for the pattern <p><strong>Current agent version:</strong> 7.2.1.6</p> $versionLine = $paragraphSections | where {$_ -like "*Current*agent*"} $splitlines = ($versionLine.replace('<','#$%^<').replace('>','>#$%^').split('#$%^')).trim() $pattern = "(\d+\.){3}\d+" $version = [Version]::new(($splitlines | select-string -Pattern $pattern).tostring()) Write-Output $version } function Get-CurrentControlUpAgentURL { [cmdletBinding()] [outputType([string])] param( [validateSet("net45","net35")] [string]$netversion = "net45", [validateSet("x86","x64")] [string]$architecture = "x64" ) $version = Get-CurrentControlUpAgentVersion $DownloadURL = "https://downloads.controlup.com/agent/$($version.tostring())/ControlUpAgent-$($netversion)-$($architecture).msi" Write-Output $DownloadURL } # Example # Get-CurrentControlUpAgentURL -netversion net45 -architecture x64 # PowerShell Wrapper for MDT, Standalone and Chocolatey Installation - (C)2015 xenappblog.com # Example 1: Start-Process "XenDesktopServerSetup.exe" -ArgumentList $unattendedArgs -Wait -Passthru # Example 2 Powershell: Start-Process powershell.exe -ExecutionPolicy bypass -file $Destination # Example 3 EXE (Always use ' '): # $UnattendedArgs='/qn' # (Start-Process "$PackageName.$InstallerType" $UnattendedArgs -Wait -Passthru).ExitCode # Example 4 MSI (Always use " "): # $UnattendedArgs = "/i $PackageName.$InstallerType ALLUSERS=1 /qn /liewa $LogApp" # (Start-Process msiexec.exe -ArgumentList $UnattendedArgs -Wait -Passthru).ExitCode Clear-Host Write-Verbose "Setting Arguments" -Verbose $StartDTM = (Get-Date) $Vendor = "SmartX" $Product = "ControlUp Agent x64" $Version = "$(Get-CurrentControlUpAgentVersion)" $PackageName = "ControlUpAgent-net45-x64" $InstallerType = "msi" $Source = "$PackageName" + "." + "$InstallerType" $LogPS = "${env:SystemRoot}" + "\Temp\$Vendor $Product $Version PS Wrapper.log" $LogApp = "${env:SystemRoot}" + "\Temp\$PackageName.log" $Destination = "${env:ChocoRepository}" + "\$Vendor\$Product\$Version\$packageName.$installerType" $UnattendedArgs = "/i $PackageName.$InstallerType ALLUSERS=1 /qn /liewa $LogApp" $url = "$(Get-CurrentControlUpAgentURL)" $ProgressPreference = 'SilentlyContinue' Start-Transcript $LogPS if ( -Not (Test-Path -Path $Version ) ) { New-Item -ItemType directory -Path $Version CD $Version [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" Invoke-WebRequest -Uri $url -OutFile "$Source" } Else { Write-Verbose "File exists. Skipping Download." -Verbose CD $Version } 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 |