Created
January 27, 2022 19:27
-
-
Save jmconway/84ccc72fc34613a061ffa098f15cd683 to your computer and use it in GitHub Desktop.
Two functions I wrote for our Windows 10 21H2 Enterprise imaging process: Set-OptionalFeatures with the features I like disabled and enabled; Remove-AppxPackages for removing first individual AppxPackages that aren't necessary to Windows 10 for all users, and then removing the Provisioned AppxPackages associated from the live Windows image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Set-OptionalFeatures { | |
# Features we want to disable by default | |
$toDisable = "Internet-Explorer-Optional-amd64","MicrosoftWindowsPowerShellV2","MicrosoftWindowsPowerShellV2Root","Printing-XPSServices-Features","WCF-Services45","WCF-TCP-PortSharing45","WindowsMediaPlayer","WorkFolders-Client" | |
foreach ($feature in $toDisable) { | |
Get-WindowsOptionalFeature -Online -FeatureName $feature | Disable-WindowsOptionalFeature -Online -NoRestart -Remove -Verbose | |
} | |
# Features we want to enable by default | |
$toEnable = "Containers", "Containers-DisposableClientVM","Windows-Defender-ApplicationGuard", "Microsoft-Windows-Subsystem-Linux" | |
foreach ($feature in $toEnable) { | |
Try { | |
Get-WindowsOptionalFeature -Online -FeatureName $feature | Enable-WindowsOptionalFeature -Online -NoRestart -Verbose | |
} Catch [Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand] { | |
Write-Host "$feature could not be enabled and may need a parent feature as a prerequisite" | |
} | |
} | |
} | |
function Remove-AppxPackages { | |
$appx = "Microsoft.BingWeather", "Microsoft.GetHelp", "Microsoft.Getstarted", "Microsoft.MicrosoftOfficeHub", "Microsoft.MicrosoftSolitaireCollection", "Microsoft.Office.OneNote", "Microsoft.People", "Microsoft.SkypeApp", "Microsoft.Wallet", "microsoft.windowscommunicationsapps", "Microsoft.WindowsFeedbackHub", "Microsoft.WindowsMaps", "Microsoft.YourPhone", "Microsoft.ZuneMusic", "Microsoft.ZuneVideo" | |
foreach ($app in $appx) { | |
# Found that running as built-in Administrator while in MDT deployment or manually running the script, some AppX Packages don't like the -AllUsers parameter on the Remove-AppxPackage cmdlet | |
Try { | |
Get-AppxPackage -AllUsers -Name $app | Remove-AppxPackage -AllUsers -Verbose | |
} # These Packages will throw a COMException below, catch this error and run without the -AllUsers parameter | |
Catch [System.Runtime.InteropServices.COMException] { | |
Get-AppxPackage -AllUsers -Name $app | Remove-AppxPackage -Verbose | |
} | |
} | |
$provisioned = "Microsoft.BingWeather", "Microsoft.GetHelp", "Microsoft.Getstarted", "Microsoft.MicrosoftOfficeHub", "Microsoft.MicrosoftSolitaireCollection", "Microsoft.Office.OneNote", "Microsoft.People", "Microsoft.SkypeApp", "Microsoft.Wallet", "microsoft.windowscommunicationsapps", "Microsoft.WindowsFeedbackHub", "Microsoft.WindowsMaps", "Microsoft.YourPhone", "Microsoft.ZuneMusic", "Microsoft.ZuneVideo" | |
foreach ($app in $provisioned) { | |
Get-AppxProvisionedPackage -Online | Where-Object {$_.PackageName -like $app} | Remove-AppxProvisionedPackage -Online -PackageName $app -Verbose | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment