$errorActionPreference = "SilentlyContinue"
If ($ENV:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
Try {
&"$ENV:WINDIR\SysNative\WindowsPowershell\v1.0\PowerShell.exe" -ExecutionPolicy bypass -NoProfile -File $PSCOMMANDPATH
}
Catch {
Throw "Failed to start $PSCOMMANDPATH"
}
Exit
}
#App Details
$str_App = 'JAWSR202121ENGC1 - Freedom Scientific JAWS 2021'
$str_PackageCode = 'JAWSR202121ENGC1'
$str_UninstallExe = 'MsiExec.exe'
$str_UninstallExe1 = "c:\Programdata\Package Cache\{4de0dac0-e7b5-4fbd-8370-86df7920062d}\JAWS setup package.exe"
$str_UninstallExe2 = "C:\Program Files\Freedom Scientific\FSReader\3.0\UninstallFSReader.exe"
$str_Token1 = $args[0]
$str_Token2 = $args[1]
#Create Log folder
$Str_ProgramData = $env:ProgramData
$Str_LogFolder = "$Str_ProgramData\IntuneWin32Apps"
if(!(Test-Path -Path $Str_LogFolder )){
New-Item -ItemType directory -Path $Str_LogFolder
}
$str_LogFile = "$Str_LogFolder\IntuneWin32Apps_Uninstall.log"
#Write App
$str_LogEntry = "$(Get-Date) ; $str_App"
Add-Content $str_LogFile $str_LogEntry
#Write Version
$str_LogEntry = "$(Get-Date) ; Version 1"
Add-Content $str_LogFile $str_LogEntry
If (test-path $str_UninstallExe1){
$str_UninstallExe1 = "c:\Programdata\Package Cache\{4de0dac0-e7b5-4fbd-8370-86df7920062d}\JAWS setup package.exe"
$Arguments = "/uninstall /quiet"
$AppName = "Freedom Scientific JAWS 2021.2103.174.400"
$str_LogEntry = "$(Get-Date) ; Uninstalling $AppName"
Add-Content $str_LogFile $str_LogEntry
$str_LogEntry = "$(Get-Date) ; Install Command: $str_UninstallExe1 $Arguments"
Add-Content $str_LogFile $str_LogEntry
$process = (start-process -filepath $str_UninstallExe1 -argumentlist $Arguments -wait -PassThru)
$exitcode = $process.ExitCode
$str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode"
Add-Content $str_LogFile $str_LogEntry
}
Else {
$str_LogEntry = "$(Get-Date) ; Freedom Scientific JAWS 2021.2103.174.400 not installed"
Add-Content $str_LogFile $str_LogEntry
}
If (test-path $str_UninstallExe2){
$str_UninstallExe2 = "C:\Program Files\Freedom Scientific\FSReader\3.0\UninstallFSReader.exe"
$Arguments = "/S"
$AppName = "Freedom Scientific FSReader 3.5.210.0"
$str_LogEntry = "$(Get-Date) ; Uninstalling $AppName"
Add-Content $str_LogFile $str_LogEntry
$str_LogEntry = "$(Get-Date) ; Install Command: $str_UninstallExe2 $Arguments"
Add-Content $str_LogFile $str_LogEntry
$process = (start-process -filepath $str_UninstallExe2 -argumentlist $Arguments -wait -PassThru)
$exitcode = $process.ExitCode
$str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode"
Add-Content $str_LogFile $str_LogEntry
}
Else {
$str_LogEntry = "$(Get-Date) ; Freedom Scientific FSReader 3.5.210.0 not installed"
Add-Content $str_LogFile $str_LogEntry
}
$Array = @(
[pscustomobject]@{MSIGUID='{BD25E96E-17B1-487B-8342-0406697FC48D}';APPNAME='Freedom Scientific Telemetry 3.3.6.0'}
[pscustomobject]@{MSIGUID='{92F55251-4B8C-4159-98FE-B6744E925E0D}';APPNAME='RDP Support 23.3.4.0'}
[pscustomobject]@{MSIGUID='{C9FFAB1B-D20C-46CC-B72E-F1A2038A005C}';APPNAME='Freedom Scientific USB Camera Driver 14.0.40.101'}
[pscustomobject]@{MSIGUID='{C7389029-7C1B-4FF2-8A81-F1136ABAA94D}';APPNAME='Keyboard Manager 3.3.6.400'}
[pscustomobject]@{MSIGUID='{11C9F4EE-775E-469C-A983-8A2935B0B71D}';APPNAME='Freedom Scientific Authorization 7.3.2.0'}
[pscustomobject]@{MSIGUID='{481435FF-97AC-11E6-8DDB-64006A5729E1}';APPNAME='Freedom Scientific Fusion Interface 2.100.7.0'}
[pscustomobject]@{MSIGUID='{4466ADE6-D352-4BFF-904C-B7948BA89982}';APPNAME='Freedom Scientific Touch Server 3.0.3001.0'}
[pscustomobject]@{MSIGUID='{136F1D08-5DD2-4B52-8B2E-FA70AFE505A5}';APPNAME='Freedom Scientific Error Reporting 8.3.5.0'}
[pscustomobject]@{MSIGUID='{1CCBF2EE-E481-4A55-B7AF-EE729078B5EE}';APPNAME='FSOcrTombstone 14.0.700'}
[pscustomobject]@{MSIGUID='{194B7DA0-20B8-4E8B-9AFB-4D893187A9A9}';APPNAME='Freedom Scientific Ocr 19.3.3.0'}
[pscustomobject]@{MSIGUID='{E63CDB0E-C508-44CA-AE57-8733ACA0AEDC}';APPNAME='Freedom Scientific OmniPage 20 18.0.10.0'}
[pscustomobject]@{MSIGUID='{AE1E7553-752E-4D04-9695-EE1FB83C54AE}';APPNAME='Freedom Scientific JAWS Training Table Of Contents DAISY Files 22.0.58.0'}
[pscustomobject]@{MSIGUID='{92BFB73A-4A8F-42DD-AFC9-16A91A2902D3}';APPNAME='Freedom Scientific WOW64 Proxy 21.0.3000.0'}
[pscustomobject]@{MSIGUID='{B5B7D6B7-111D-4A6A-824D-EB4631F5C722}';APPNAME='Freedom Scientific HookManager 3.0.3001.0'}
[pscustomobject]@{MSIGUID='{6C654742-DA97-4B78-B1CA-A0859A9B1243}';APPNAME='Freedom Scientific UIAHooks 22.3.8.0'}
[pscustomobject]@{MSIGUID='{D1B43B83-02A9-4D36-BBC4-ED34532D728D}';APPNAME='Freedom Scientific Synth 22.3.8.0'}
[pscustomobject]@{MSIGUID='{AF6A5953-FE5F-451C-BD86-D0EB3F76A6E0}';APPNAME='Freedom Scientific Elevation 22.3.8.0'}
[pscustomobject]@{MSIGUID='{FAEE61D3-2A5E-4F7F-926F-77AAC08CE4DD}';APPNAME='Sentinel System Driver Installer 7.5.0 7.5.0'}
[pscustomobject]@{MSIGUID='{A334FFCA-53ED-4C84-9A60-48CA885382AB}';APPNAME='Freedom Scientific Utilities 22.3.11.0'}
[pscustomobject]@{MSIGUID='{38464CAB-C140-4C39-BE4C-C68D062130DA}';APPNAME='Freedom Scientific Video Accessibility 12.6.352.0'}
[pscustomobject]@{MSIGUID='{F4DA19E5-A560-4313-8623-3493DCE3C681}';APPNAME='Freedom Scientific Synthesizer Eloquence 6.1.8'}
[pscustomobject]@{MSIGUID='{72596573-EEDF-4173-BF45-71E8FA0067DD}';APPNAME='Freedom Scientific Ocr 19.3.3.0'}
[pscustomobject]@{MSIGUID='{9CBFFF67-CB9F-4D77-9093-1B456381EC9D}';APPNAME='FSOcrTombstone 14.0.700'}
)
#Loop Through Array
For ($num = 0 ; $num -le $Array.count-1 ; $num++) {
$AppName = $Array[$num].APPNAME
$MSIGUID = $Array[$num].MSIGUID
$UninstallExe = 'MsiExec.exe'
$Arguments = "/X $MSIGUID REBOOT=ReallySuppress MSIRESTARTMANAGERCONTROL=Disable /QN"
$process = (start-process -filepath $UninstallExe -argumentlist $Arguments -wait -PassThru)
$exitcode = $process.ExitCode
#Check if another MSI install already in progress
While($exitcode -eq '1618'){
$str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode, MSI install in progress - wait 10 seconds and reinstall"
Add-Content $str_LogFile $str_LogEntry
#Wait patiently
Start-Sleep -Seconds 10
#Update regCheck
$process = (start-process -filepath $UninstallExe -argumentlist $Arguments -wait -PassThru)
$exitcode = $process.ExitCode
}
If($exitcode -eq '1605') {
$str_LogEntry = "$(Get-Date) ; $AppName not installed"
Add-Content $str_LogFile $str_LogEntry
} Else{
$str_LogEntry = "$(Get-Date) ; Uninstalling $AppName"
Add-Content $str_LogFile $str_LogEntry
$str_LogEntry = "$(Get-Date) ; Uninstall Command: $UninstallExe $Arguments"
Add-Content $str_LogFile $str_LogEntry
$str_LogEntry = "$(Get-Date) ; Exit Code: $exitcode"
Add-Content $str_LogFile $str_LogEntry
}
}
#--------------------------------
#Remove User from Uninstall Group
Import-Module SaC.MSGraph-AuthToken
# Get package
$UninstallGroup = "Managed W10 App - $str_PackageCode - Uninstall"
$URI = "https://graph.microsoft.com/v1.0/groups?`$filter=startswith(displayName,`'$($UninstallGroup)`')"
# Get AAD Auth token
$Request = Get-BearerToken $str_Token1 $str_Token2
$token = $Request.access_token
$headers = @{ "Authorization" = "Bearer " + $token }
# Get UPN
$username = Get-WmiObject Win32_Process -Filter "Name='explorer.exe'" | ForEach-Object { $_.GetOwner() } | Select-Object -Unique -Expand User
$userUPN = ($username + '@unilever.com').ToLower()
$str_LogEntry = "$(Get-Date) ; User UPN $userUPN"
Add-Content $str_LogFile $str_LogEntry
# Get user ID via the users UPN
$myProfile = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/users/$($userUPN)/" -Headers $headers -Method GET -ContentType "application/json"
$myId = $myProfile.id
# Create body of request and convert to json
$body = @{ "@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/$($myId)" } | ConvertTo-Json
# Get group ID
$groupMetaData = Invoke-RestMethod -Uri $URI -Headers $headers -Method GET -ContentType "application/json"
$groupId = $groupMetaData.value[0].id
# Remove User from Group
$response = Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/groups/$($groupId)/members/$($myId)/`$ref" -Headers $headers -Method DELETE -Body $body -ContentType "application/json"
# Log File
$str_LogEntry = "$(Get-Date) ; User removed from $UninstallGroup"
Add-Content $str_LogFile $str_LogEntry
#--------------------------------
#Delete Uninstall Detection Key
Remove-ItemProperty -Path 'HKLM:\SOFTWARE\Unilever\IntuneWin32Apps' -Name "$str_PackageCode Uninstall Group" -Force
$str_LogEntry = "$(Get-Date) ; HKLM:\SOFTWARE\Unilever\IntuneWin32Apps\$str_PackageCode Uninstall Group Reg Key Deleted"
Add-Content $str_LogFile $str_LogEntry
#Uninstall Completed
$str_LogEntry = "$(Get-Date) ; Uninstall Completed"
Add-Content $str_LogFile $str_LogEntry
#Close Log File
$str_LogEntry = "-----------------------"
Add-Content $str_LogFile $str_LogEntry
No comments:
Post a Comment