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