<
<#
.SYNOPSIS
This is AppxPackage removal script for the autopilot build devices
.DESCRIPTION
RemoveAppxPackage
.PARAMETER
Default Parametername
.EXAMPLE
powershell -executionpolicy bypass -file RemoveAppxPackage.ps1
.NOTES
NAME: <RemoveAppxPackage>
AUTHOR: Kamalakannan
KEYWORDS: Keyword1
.CHANGE
Author : Kamal 25/01/2023
Version 1.0
#>
Function main {
## Allows the use of -WhatIf
[CmdletBinding(SupportsShouldProcess=$True)]
param(
## LogFile path for the transcript to be written to
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=0)]
$LogFile = ("C:\xyz\LOGS\"+"RemoveAppxPackage"+'.log'),
## All verbose outputs will get logged in the transcript($logFile)
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=2)]
$VerbosePreference = "Continue",
## All errors should be withheld from the console
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=3)]
$ErrorActionPreference = "SilentlyContinue"
)
## Begin the timer
$Starters = (Get-Date)
## Check $VerbosePreference variable, and turns -Verbose on
Function global:Write-Verbose ( [string]$Message ) {
if ( $VerbosePreference -ne 'SilentlyContinue' ) {
Write-Host "$Message" -ForegroundColor 'Green'
}
}
Start-Transcript -Path $LogFile
Write-Verbose "Start time: $starters"
## Check $VerbosePreference variable, and turns -Verbose on
Function global:Write-Verbose ( [string]$Message ) {
if ( $VerbosePreference -ne 'SilentlyContinue' ) {
Write-Host "$Message" -ForegroundColor 'Green'
}
}
Function Removeappx
{
$applist = @("*communications*"
"*camera*"
"*dolbyaccess*"
"*fitbitcoach*"
"*officehub*"
"*solitairecollection*"
"*Teams*"
"*bingfinance*"
"*zunevideo*"
"*bingnews*"
"*people*"
"*windowsphone*"
"*phototastic*"
"*picsart*"
"*plex*"
"*skypeapp*"
"*SpotifyMusic*"
"*bingsports*"
"*bingweather*"
"*xbox*")
foreach ($app in $applist)
{
Write-Host "Searching for Appx Provisioned Package: $app"
Get-AppxPackage $app | Remove-AppxPackage
$pkglist = Get-AppxProvisionedPackage -online | Where-Object DisplayName -Like $app
if ($pkglist -ne $null)
{
foreach ($pkg in $pkglist)
{
Write-Host "Removing Appx Provisioned Package: $app"
Remove-AppxProvisionedPackage -online -packagename $pkg.PackageName
}
}
else
{
Write-Host "Unable to find package $app"
}
}
}
Removeappx
## Completed Successfully!
Write-Host (Stop-Transcript) -ForegroundColor Green
}
main
Leave a comment