Upload files to "App Uninstall Scripts"
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<#
|
||||
Author: Gabe Kerntke
|
||||
Date: 03-13-2024
|
||||
|
||||
.Synopsis
|
||||
|
||||
.Modified
|
||||
2024-03-13 (GabeK) - Original script created
|
||||
|
||||
#>
|
||||
|
||||
######################
|
||||
### Variables ###
|
||||
######################
|
||||
$Name = "SaRAcmd"
|
||||
$FileName = $Name + ".exe"
|
||||
$EPCacheLocal = "$Env:windir\NCentral\Cache"
|
||||
$Global:EPCacheLocalLocation = $ENV:EPCacheLocal + '\' + $Name + '\' + $FileName
|
||||
$InstallParameters = "-S OfficeScrubScenario -AcceptEula -OfficeVersion All"
|
||||
|
||||
######################
|
||||
### 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 "$App_Name or $App_Name2 successfully uninstalled, recommend rebooting."
|
||||
Start-Sleep 5
|
||||
Remove-Item "$EPCacheLocal\$Name" -Force -Recurse
|
||||
Remove-Item "$EPCacheLocal\SaRa.zip" -Force
|
||||
}
|
||||
ElseIf ($ExitCode -eq 3010) {
|
||||
Write-Host "$App_Name or $App_Name2 successfully removed, but requires a reboot to complete."
|
||||
Start-Sleep 5
|
||||
Remove-Item "$EPCacheLocal\$Name" -Force -Recurse
|
||||
Remove-Item "$EPCacheLocal\SaRa.zip" -Force
|
||||
}
|
||||
Else {
|
||||
Write-Host `n
|
||||
Start-Sleep 5
|
||||
Write-Host "$App_Name or $App_Name2 failed to uninstall. Exit Code:" + $ExitCode
|
||||
Remove-Item "$EPCacheLocal\$Name" -Force -Recurse
|
||||
Remove-Item "$EPCacheLocal\SaRa.zip" -Force
|
||||
}
|
||||
}
|
||||
|
||||
Function Check {
|
||||
$App_Name = "Microsoft 365"
|
||||
$Applist = Get-Software | Where-Object { $_.DisplayName -like "*$App_Name*" }
|
||||
$App_Name2 = "Microsoft Office"
|
||||
$Applist2 = Get-Software | Where-Object { $_.DisplayName -like "*$App_Name2*" }
|
||||
If ($Applist.DisplayName -like "*$App_Name*") {
|
||||
Write-Host "$App_Name is installed, proceeding with uninstall."
|
||||
Download
|
||||
}
|
||||
ElseIf ($Applist2.DisplayName -like "*$App_Name2*") {
|
||||
Write-Host "$App_Name2 is installed, proceeding with uninstall."
|
||||
Download
|
||||
}
|
||||
Else {
|
||||
Write-Host "$App_Name or $App_Name2 is not installed, exiting script."
|
||||
}
|
||||
}
|
||||
|
||||
Function Download {
|
||||
Invoke-WebRequest -UseBasicParsing "https://aka.ms/SaRA_EnterpriseVersionFiles" -OutFile "$EPCacheLocal\SaRa.zip"
|
||||
Extract
|
||||
}
|
||||
|
||||
Function Extract {
|
||||
Expand-Archive -Path "$EPCacheLocal\SaRa.zip" -DestinationPath "$EPCacheLocal\$Name"
|
||||
Run
|
||||
}
|
||||
|
||||
Function Run {
|
||||
$Install = Start-Process $EPCacheLocalLocation -ArgumentList $InstallParameters -Wait -PassThru
|
||||
$ExitCode = ($Install).ExitCode
|
||||
ExitCode
|
||||
}
|
||||
|
||||
######################
|
||||
### Script start ###
|
||||
######################
|
||||
Check
|
||||
Reference in New Issue
Block a user