<# Author: Gabe Kerntke Date: 03-13-2024 .Synopsis .Modified 2024-03-13 (GabeK) - Original script created #> # Variables $Name = "Plantronics Hub Software" $FileName = $Name + ".exe" $EPCacheLocal = "$Env:windir\NCentral\Cache" $Global:EPCacheLocalLocation = $ENV:EPCacheLocal + '\' + $FileName $InstallParameters = "/quiet /norestart" # Functions #Function checks for 32 or 64 bit processor and then pulls list of applications accordingly Function Get-Software ($CPU = $ENV:PROCESSOR_ARCHITECTURE) { If ($CPU -eq 'AMD64') { $64bit = Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* $32bit = Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* $32bit + $64bit } Else { Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* } } Function ExitCode { If ($ExitCode -eq 0) { Write-Host "$Name successfully installed." Start-Sleep 5 Remove-Item $EPCacheLocalLocation -Force } ElseIf ($ExitCode -eq 3010) { Write-Host "$Name successfully installed, but requires a reboot to complete." Start-Sleep 5 Remove-Item $EPCacheLocalLocation -Force } Else { Write-Host `n Start-Sleep 5 Write-Host "$Name failed to install. Exit Code:" + $ExitCode Remove-Item $EPCacheLocalLocation -Force } } Function Uninstall { $Uninstall = Get-WmiObject Win32_Product -filter "name like '$Name'" | ForEach-Object { $_.Uninstall() } $Value = $Uninstall | Select-Object -ExpandProperty ReturnValue If ($Value -eq "0") { Write-Host "$Name uninstalled successfully, proceeding to reinstall newest version." Download } else { Uninstall2 } } Function Uninstall2 { Get-Process | Where-Object { $_ -like "*Plantronics*" } | Select-Object -ExpandProperty ProcessName | ForEach-Object { Stop-Process -Force } -ErrorAction SilentlyContinue $Path = Get-ChildItem "C:\ProgramData\Package Cache" -Recurse | Where-Object { $_ -like "*PlantronicsHubBootstrapper.exe*" } | Select-Object -ExpandProperty Directory | Select-Object -ExpandProperty Name foreach ($Item in $Path) { Start-Process "C:\ProgramData\Package Cache\$Item\PlantronicsHubBootstrapper.exe" -ArgumentList "/uninstall /norestart /quiet" } Start-Sleep 10 $Applist2 = Get-Software | Where-Object { $_.DisplayName -like "*$Name*" } If ($Applist2.DisplayName -like "*$Name*") { Write-Host "Failed to uninstall $Name, exiting script." } Else { Write-Host "$Name uninstalled successfully, proceeding to reinstall newest version." Download } } Function Download { #VARIABLES $initialURL = "https://downloads.poly.com/headsets/PlantronicsHubInstaller.exe" Invoke-WebRequest -UseBasicParsing $initialURL -OutFile $EPCacheLocalLocation Install } Function Install { $Install = Start-Process $EPCacheLocalLocation -ArgumentList $InstallParameters -Wait -PassThru $ExitCode = ($Install).ExitCode ExitCode } # Script start #Check if App is installed $Applist = Get-Software | Where-Object { $_.DisplayName -like "*$Name*" } If ($Applist.DisplayName -like "*$Name*") { Write-Host "$Name is installed, proceeding with reinstall." Uninstall } Else { Write-Host "$Name is not installed, exiting script." }