#!ps #timeout=1000000 $registryPathDS = "HKLM:\SOFTWARE\RuffianSoftware\TechIdentityManager\" # Check if the registry key exists $keyExistsDS = Test-Path -Path $registryPathDS # Output the result if ($keyExistsDS) { Write-Output "Data found indicating installation of TechIDAgent" } else { Write-Error "No Data found indicating installation of TechIDAgent - NOT UPDATING" exit 0 } $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 [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 thier 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-process -nonewwindow -wait "$PathRS\$version\TechIDAgent.exe" -argumentlist update