Skip to content

Instantly share code, notes, and snippets.

@tsfahmed2
Created September 22, 2021 00:25
Show Gist options
  • Select an option

  • Save tsfahmed2/0f4ed14473af69da45c6c7841221db69 to your computer and use it in GitHub Desktop.

Select an option

Save tsfahmed2/0f4ed14473af69da45c6c7841221db69 to your computer and use it in GitHub Desktop.
$exitCode = 0
if (![System.Environment]::Is64BitProcess)
{
# start new PowerShell as x64 bit process, wait for it and gather exit code and standard error output
$sysNativePowerShell = "$($PSHOME.ToLower().Replace("syswow64", "sysnative"))\powershell.exe"
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $sysNativePowerShell
$pinfo.Arguments = "-ex bypass -file `"$PSCommandPath`""
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.CreateNoWindow = $true
$pinfo.UseShellExecute = $false
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$exitCode = $p.ExitCode
$stderr = $p.StandardError.ReadToEnd()
if ($stderr) { Write-Error -Message $stderr }
}
else
{
# start logging to TEMP in file "scriptname".log
Start-Transcript -Path "$env:TEMP\$($(Split-Path $PSCommandPath -Leaf).ToLower().Replace(".ps1",".log"))" | Out-Null
function Get-InstalledApps
{
#Write-host 'Start Get-InstalledApps'
if ([IntPtr]::Size -eq 4) {
$regpath = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
#Write-host 'Found x86'
}
else {
$regpath = @(
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
)
#Write-host 'Found x64'
}
Get-ItemProperty $regpath | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Select-Object * | Sort DisplayName
}
############################
$wadk = Get-InstalledApps | where {$_.DisplayName -match "Windows Assessment and Deployment Kit Windows Preinstallation Environment Add-ons - Windows 10"}
################################
$isopenmanageinstalled = Get-InstalledApps | where {$_.DisplayName -match "Inventory Agent"}
if($isopenmanageinstalled){
Write-Host "Dell inventorty agent detected $isopenmanageinstalled"
Write-Host $isopenmanageinstalled
ForEach ($u in $isopenmanageinstalled)
{
$UnInstall = $u.UninstallString
$UnInstall = $UnInstall.Trim()
$UnInstall = $UnInstall -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$UnInstall = $UnInstall.Trim()
start-process "msiexec.exe" -arg "/X $UnInstall /qn" -Wait
$isopenmanageinstalled = Get-InstalledApps | where {$_.DisplayName -match "Inventory Agent"}
Write-Host "After running uninstaller"
Write-Host "$isopenmanageinstalled"
}
}
$isdellSupportAssistInstalled = Get-InstalledApps | where {$_.DisplayName -eq "Dell SupportAssist"}
if($isdellSupportAssistInstalled){
Write-Host "Running uninstall Dell support assist detected $isdellSupportAssistInstalled"
ForEach ($u in $isdellSupportAssistInstalled)
{
$UnInstall = $u.UninstallString
$UnInstall = $UnInstall.Trim()
$UnInstall = $UnInstall -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$UnInstall = $UnInstall.Trim()
start-process "msiexec.exe" -arg "/X $UnInstall /qn" -Wait
$isdellSupportAssistInstalled = Get-InstalledApps | where {$_.DisplayName -eq "Dell SupportAssist"}
Write-Host "Ran uninstall for Dell support assist"
Write-Host $isdellSupportAssistInstalled
}
}
$isdellSupportOSPlugin = Get-InstalledApps | where {$_.DisplayName -eq "Dell SupportAssist OS Recovery Plugin for Dell Update"}
if($isdellSupportOSPlugin){
Write-Host "Running uninstall Dell support assist detected $isdellSupportOSPlugin"
ForEach ($u in $isdellSupportOSPlugin)
{
$UnInstall = $u.UninstallString
$UnInstall = $UnInstall.Trim()
$UnInstall = $UnInstall -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$UnInstall = $UnInstall.Trim()
start-process "msiexec.exe" -arg "/X $UnInstall /qn" -Wait
$isdellSupportOSPlugin = Get-InstalledApps | where {$_.DisplayName -eq "Dell SupportAssist OS Recovery Plugin for Dell Update"}
Write-Host "Ran uninstall for Dell SupportAssist OS Recovery Plugin for Dell Update"
Write-Host $isdellSupportOSPlugin
}
}
$isdellcuuwpinstalled = Get-InstalledApps | where {$_.DisplayName -eq "Dell Command | Update for Windows 10"}
if($isdellcuuwpinstalled){
ForEach ($u in $isdellcuuwpinstalled)
{
Write-Host "Dell command update for windows 10 found installed $isdellcuuwpinstalled"
$UnInstall = $u.UninstallString
$UnInstall = $UnInstall.Trim()
$UnInstall = $UnInstall -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$UnInstall = $UnInstall.Trim()
start-process "msiexec.exe" -arg "/X $UnInstall /qn" -Wait
$isdellcuuwpinstalled = Get-InstalledApps | where {$_.DisplayName -eq "Dell Command | Update for Windows 10"}
Write-Host " FInished running uninstall for dell cu uwp"
Write-Host $isdellcuuwpinstalled
}
}
Stop-Transcript | Out-Null
}
exit $exitCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment