#!ps #timeout=1000000 param( [Parameter(Mandatory=$true)] [string]$ClientGuid, # Capture all remaining arguments. [Parameter(ValueFromRemainingArguments = $true)] [string[]]$OtherArgs ) # check the ClientGuid to make sure it is set. It is the only one that must be set. if ($ClientGuid -eq '' -or $ClientGuid -eq $null ) { Write-Error '$ClientGuid needs to be set' -ErrorAction Stop } $version = 'TechIDAgent_6.877windows' $PathRS = 'c:\Program Files\Ruffian Software' $SourceFile = "https://ch001.ruffiansoftware.com/release/files/TechIDAgent.Windows.6.877.zip" if ($SourceFile -like "{{*") { $SourceFile = "https://ch001.ruffiansoftware.com/release/files/TechIDAgent.Windows.6.877.zip" } $DestFile = "$PathRS\$version.zip" New-Item -ItemType Directory -Force -Path $PathRS if (Test-Path "$DestFile") { Remove-Item "$DestFile" # seems like we need to delay before overwritting a file we just deleted? Start-Sleep 2 } # some older systems have to be told what TLS to use because they default to 1.1 which is no longer supported # if your systems are up to date, then you do not need the following line. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Invoke-WebRequest -Uri "$SourceFile" -OutFile "$DestFile" # do a simple hash check to make sure we got a file that we are expecting. # This is only one of many ways we at Ruffian Software fight supply chain attacks. Everyone needs to do their part. $hash = (Get-FileHash -Path "$DestFile").Hash if ($hash -ne "84212ec2e0328ecab876dd160e0fee584ce11889dc77ea90037be25edf3093e6") { Write-Error 'Hash of downloaded file does not match expected value.' -ErrorAction Stop } # make sure the path we are about to expand into doesn't already have an executable there. if (Test-Path "$PathRS\$version\TechIDAgent.exe") { start-process -nonewwindow -wait "$PathRS\$version\TechIDAgent.exe" -argumentlist uninstall Remove-Item -Recurse -Force "$PathRS\$version" # seems like we need to delay before overwritting a file we just deleted? Start-Sleep 2 } Expand-Archive -LiteralPath "$DestFile" -DestinationPath "$PathRS\$version" # start the install of this version. # have to set the clientguid first start-process -nonewwindow -wait "$PathRS\$version\TechIDAgent.exe" -argumentlist @("clientid", "$ClientGuid") start-process -nonewwindow -wait "$PathRS\$version\TechIDAgent.exe" -argumentlist install if ($OtherArgs -and $OtherArgs.Count -gt 0) { & "$PathRS\$version\TechIDAgent.exe" @OtherArgs } # you can add other parameter setting here..... # if you add to this script you will need to remove the signature, or resign it after your changes # note the escaping of argumentlists in powershell as above with '"' + ... + '"' around arguments with spaces in them # start-process -nonewwindow -wait "$PathRS\$version\TechIDAgent.exe" -argumentlist @("otheroption", '"' + $ClientGuid + '"') start-process -nonewwindow -wait "$PathRS\$version\TechIDAgent.exe" -argumentlist start