Question

Remove windows apps

  • 7 January 2022
  • 1 reply
  • 534 views

Hi,

I try script (worklet) for remove apps windows 10 (Spotify and WindowsStores.

But dont work, anyone idea? thx.

Script:

Start-Transcript -Path C:\SetupLog.txt -NoClobber
Write-Output "Uninstalling default apps"
$apps = @(
"Microsoft.WindowsStore"
"SpotifyAB.SpotifyMusic"
)

foreach ($app in $apps) {
Write-Output "Trying to remove $app"

# Get the app version
$appVersion = (Get-AppxPackage -Name $app).Version

If ($appVersion){
# If the apps is found, remove it
Get-AppxPackage -Name $app -AllUsers | Remove-AppxPackage -AllUsers
}

# Remove the app from the local Windows Image to prevent re-install on new user accounts
Get-AppXProvisionedPackage -Online | Where-Object DisplayName -EQ $app | Remove-AppxProvisionedPackage -Online

# Cleanup Local App Data
$appPath="$Env:LOCALAPPDATA\Packages\$app*"
Remove-Item $appPath -Recurse -Force -ErrorAction 0
}

 

 


1 reply

Below is our worklet to uninstall a Windows app - keep in mind, you need to enter the name/syntax of the app exactly as it appears in the “Apps and Features” folder (this is mentioned in the worklet). 

EVALUATION CODE

<#
.SYNOPSIS
Uninstall Application by Name - Evaluation Script
OS Support: Windows 7 and above
Required modules: NONE
.DESCRIPTION
This worklet is designed to grant an Admin the ability to uninstall an application with minimal knowledge of the bitness,
installer type, or uninstall command line. By placing an application name between the single quotes, the worklet will
scan the registry for the matching application. If the application is found, it will exit with an Exit code of '1' and
flag the device for remediation.

Usage:
$appName: The application name provided must match exactly as it is displayed in "Programs and Features" (Add or
Remove Programs) for Win7/8.1, and "Apps and Features" for Win10. Universal Windows Platform (UWP) applications are
not currently supported in this worklet.

Additional Notes:
Some software (such as M365 Apps) installs as a "suite" even though each component could have its own registry entry.
This type of installation is not supported with this worklet. For more information please see the software vendor's
support documentation.
.EXAMPLE
$appName = '7-Zip 19.00 (x64)'
.EXAMPLE
$appName = 'Microsoft Silverlight'
.NOTES
Author: eliles,rrodriguez
Date: February 24, 2021
#>

# Using scriptblock to relaunch in native environment for 64bit detection.
$scriptBlock = {

######## Make changes within the block ########
# Add Application name exactly as it appears in Add/Remove Programs, Programs and Features, or Apps and Features between single quotes.
$appName = ''
###############################################

# Define registry location for uninstall keys
$uninstReg = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')

# Get all entries that match our criteria. DisplayName matches $appName (using -like to support special characters)
$installed = @(Get-ChildItem $uninstReg -ErrorAction SilentlyContinue | Get-ItemProperty | Where-Object {($_.DisplayName -like $appName)})

# If any matches were found, $installed will return a "1" and pass it to $exitCode flagging the device for remediation.
if ($installed)
{
return 1
}
else
{
return 0
}
}

# Execution of $scriptBlock
$exitCode = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptblock

# Exit with value provided by $installed
Exit $exitCode

--------------------------------------------------------------------------------------------

REMEDIATION CODE

<#
.SYNOPSIS
Uninstall Application by Name - Remediation Script
OS Support: Windows 7 and above
Required modules: NONE
.DESCRIPTION
This worklet is designed to grant an Admin the ability to uninstall an application with minimal knowledge of the bitness,
installer type, or uninstall command line. By placing an application name between the single quotes, the worklet will
scan the registry for the matching application, and perform an uninstall based on the applications "UninstallString".

Usage:
$appName: The application name provided must match exactly as it is displayed in "Programs and Features" (Add or
Remove Programs) for Win7/8.1, and "Apps and Features" for Win10. Universal Windows Platform (UWP) applications are
not currently supported in this worklet.

$exeCmd: You should modify this line if the application was installed via an EXE Installer and has specifc parameters
to suppress restarts or perform a silent removal. Please see the software vendor's support documentation for specific
instructions. (NOTE: $exeCmd is only applied to EXE Installer removals.)

Additional Notes:
Some software (such as M365 Apps) installs as a "suite" even though each component could have its own registry entry.
This type of installation is not supported with this worklet. For more information please see the software vendor's
support documentation.
.EXAMPLE
$appName = '7-Zip 19.00 (x64)'
$exeCmd = '/S'
.EXAMPLE
$appName = 'Microsoft Silverlight'
$exeCmd = '/S'
.NOTES
Author: eliles,rrodriguez
Date: February 24, 2021
#>

# Using scriptblock to relaunch in native environment for 64bit detection.
$scriptBlock = {

# Add Application name exactly as it appears in Add/Remove Programs, Programs and Features, or Apps and Features between single quotes.
# Modify $exeCmd as needed for EXE Installer based installations that require additional settings.
######## Make changes within the block ########
$appName = ''
$exeCmd = '/S'
###############################################

# Define registry location for uninstall keys
$uninstReg = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall','HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')

# Get all entries that match our criteria. DisplayName matches $appName (using -like to support special characters)
$installed = @(Get-ChildItem $uninstReg -ErrorAction SilentlyContinue | Get-ItemProperty | Where-Object {($_.DisplayName -like $appName)})

# Initialize an array to store the uninstalled app information
$uninstalled = @()

# Start a loop in-case you get more than one match, uninstall each.
foreach ($version in $installed)
{
#For every version found, run the uninstall string
$uninstString = $version.UninstallString
#If exe, run as written + $exeCmd variable, if msiexec run as msi using the name of the reg key as the msi guid.
if($uninstString -match 'msiexec')
{
$process = Start-Process msiexec.exe -ArgumentList "/x $($version.PSChildName) /qn /norestart" -Wait -PassThru
}
else
{
$process = Start-Process $uninstString -ArgumentList $exeCmd -Wait -PassThru
}

# Check exit code for success/fail and verifying against known successful installation codes
# If unsuccessful, don't add to uninstalled list.
if (($process.ExitCode -eq '0') -or ($process.ExitCode -eq '1641') -or ($process.ExitCode -eq '3010'))
{
$uninstalled += $version.PSPath
}
}
return $uninstalled
}

$uninstalledApps = & "$env:SystemRoot\sysnative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy Bypass -WindowStyle Hidden -NoProfile -NonInteractive -Command $scriptBlock

# Use Write-Output so you can see a result in the Activity Log
Write-Output "Uninstalled the following key: $uninstalledApps"

if($uninstalledApps)
{
Write-Output "Uninstall Successful"
Exit 0
}
else
{
Write-Output "Uninstall Failed"
Exit 1
}

 

Reply