Skip to content

Commit 304fc03

Browse files
alievertzAndy Lievertz
andauthored
Development (#1)
* save commit * Initial release; v1.0.0 --------- Co-authored-by: Andy Lievertz <[email protected]>
1 parent f91e0ec commit 304fc03

File tree

4 files changed

+117
-38
lines changed

4 files changed

+117
-38
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# OZO Remove AppX Packages
2+
3+
|Date|Version|Comment|
4+
|----|-------|-------|
5+
|2025-Feb-15|1.0.0|Initial release.|

PowerShell-Remove-AppX-Packages.ps1

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
# powershell-remove-appx-packages
1+
# OZO Remove AppX Packages
2+
3+
## Description
4+
Removes provisioned AppX packages for the current user and available AppX packages from the running system. You can generate a list of your system's available AppX packages with the following in an _Administrator_ PowerShell:
5+
```powershell
6+
(Get-AppxPackage).Name
7+
```
8+
9+
## Installation
10+
This script is published to the [PowerShell Gallery](https://learn.microsoft.com/en-us/powershell/scripting/gallery/overview?view=powershell-5.1). Ensure your system is configured for this repository then execute the following in an _Administrator_ PowerShell:
11+
12+
```powershell
13+
Install-Script ozo-remove-appx-packages
14+
```
15+
16+
## Usage
17+
Run this script in an _Admininstrator_ PowerShell.
18+
```powershell
19+
ozo-remove-appx-packages
20+
-Packages <Array>
21+
```
22+
23+
## Parameters
24+
|Parameter|Description|
25+
|---------|-----------|
26+
|`Packages`|A comma-separated list of packages to remove.|
27+
28+
## Example
29+
```powershell
30+
ozo-remove-appx-packages -Packages "Microsoft.BingWeather","Microsoft.SkypeApp","Microsoft.ZuneMusic"
31+
```
32+
33+
## Acknowledgements
34+
Special thanks to my employer, [Sonic Healthcare USA](https://sonichealthcareusa.com), who has supported the growth of my PowerShell skillset and enabled me to contribute portions of my work product to the PowerShell community.

ozo-remove-appx-packages.ps1

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#Requires -Modules @{ModuleName="OZO";ModuleVersion="1.4.0"},@{ModuleName="OZOLogger";ModuleVersion="1.1.0"} -RunAsAdministrator
2+
3+
<#PSScriptInfo
4+
.VERSION 1.0.0
5+
.GUID 26313204-248b-4816-89de-4c605134b2ca
6+
.AUTHOR Andy Lievetz <[email protected]>
7+
.COMPANYNAME One Zero One
8+
.COPYRIGHT This script is released under the terms of the GNU General Public License ("GPL") version 2.0.
9+
.TAGS
10+
.LICENSEURI https://github.com/onezeroone-dev/OZO-Remove-AppX-Packages/blob/main/LICENSE
11+
.PROJECTURI https://github.com/onezeroone-dev/OZO-Remove-AppX-Packages
12+
.ICONURI
13+
.EXTERNALMODULEDEPENDENCIES
14+
.REQUIREDSCRIPTS
15+
.EXTERNALSCRIPTDEPENDENCIES
16+
.RELEASENOTES https://github.com/onezeroone-dev/OZO-Remove-AppX-Packages/blob/main/CHANGELOG.md
17+
#>
18+
19+
<#
20+
.DESCRIPTION
21+
Removes provisioned AppX packages for the current user and available AppX packages from the running system.
22+
.PARAMETER Packages
23+
A comma-separated list of packages to remove.
24+
.LINK
25+
https://github.com/onezeroone-dev/OZO-Remove-AppX-Packages/blob/main/README.md
26+
.NOTES
27+
Run this script in an Administrator PowerShell.
28+
#>
29+
[CmdLetBinding(SupportsShouldProcess=$true)]
30+
Param(
31+
[Parameter(Mandatory=$true,HelpMessage="A comma-separated list of packages to remove")][Array] $Packages
32+
)
33+
34+
Function Get-OZOUserInteractive {
35+
return [Environment]::UserInteractive
36+
}
37+
38+
# MAIN
39+
# Variables
40+
[Array] $AppxPackages = (Get-AppxPackage)
41+
[Array] $AppxProvisionedPackages = (Get-AppxProvisionedPackage -Online)
42+
# Determine if the session is user-interactive
43+
If ((Get-OZOUserInteractive) -eq $true) {
44+
# Session is user-interactive; iterate through the list of packages
45+
ForEach ($Package in $Packages) {
46+
Write-Host ("Processing available Appx packages.")
47+
# Determine if the AppxPackages array contains the package
48+
If (($AppxPackages).Name -Contains $Package) {
49+
# The array contains the package; remove it
50+
Try {
51+
Remove-AppxPackage -Package ($AppxPackages | Where-Object {$_.Name -eq $Package}).PackageFullName -ErrorAction Stop
52+
# Success
53+
Write-Host ("Removed the " + $Package + " available package.")
54+
} Catch {
55+
# Failure
56+
Write-Host ("Error removing the " + $Package + "available package. Error message is: " + $_)
57+
}
58+
} Else {
59+
Write-Host ("Did not find " + $Package + " among the available Appx packages.")
60+
}
61+
Write-Host ("Processing provisioned Appx packages.")
62+
# Determine if the AppxProvisionedPackages array contains the package
63+
If (($AppxProvisionedPackages).DisplayName -Contains $Package) {
64+
# The array contains the package; remove it
65+
Try {
66+
Remove-AppxProvisionedPackage -Online -PackageName ($AppxProvisionedPackages | Where-Object {$_.DisplayName -eq $Package}).PackageName | Out-Null
67+
Write-Host ("Removed the " + $Package + " provisioned package.")
68+
} Catch {
69+
Write-Host ("Error removing the " + $Package + "provisioned package. Error message is: " + $_)
70+
}
71+
} Else {
72+
Write-Host ("Did not find " + $Package + " among the provisioned Appx packages.")
73+
}
74+
}
75+
} Else {
76+
# Session is not user-interactive
77+
Write-OZOProvider -Message "Please run this script in a user-interactive session." -Level "Error"
78+
}

0 commit comments

Comments
 (0)