Skip to content

Commit

Permalink
Keep Windows Security (#1341)
Browse files Browse the repository at this point in the history
Adds a switch to Remove-ProvisionedPackages to determine whether we should remove Windows Security (GUI component, Microsoft.SecHealthUI).

This commit fixes issue #1339
  • Loading branch information
CodingWonders authored Jan 3, 2024
1 parent c4bf30c commit 46fdfdf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
15 changes: 14 additions & 1 deletion functions/private/MicroWin-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,20 @@ function Remove-Packages
Write-Progress -Activity "Removing Apps" -Status "Ready" -Completed
}

function Remove-ProvisionedPackages
function Remove-ProvisionedPackages([switch] $keepSecurity = $false)
{
<#
.SYNOPSIS
Removes AppX packages from a Windows image during MicroWin processing
.PARAMETER Name
keepSecurity - Boolean that determines whether to keep "Microsoft.SecHealthUI" (Windows Security) in the Windows image
.EXAMPLE
Remove-ProvisionedPackages -keepSecurity:$false
#>
$appxProvisionedPackages = Get-AppxProvisionedPackage -Path "$($scratchDir)" | Where-Object {
$_.PackageName -NotLike "*AppInstaller*" -AND
$_.PackageName -NotLike "*Store*" -and
Expand All @@ -107,6 +119,7 @@ function Remove-ProvisionedPackages

if ($?)
{
if ($keepSecurity) { $appxProvisionedPackages = $appxProvisionedPackages | Where-Object { $_.PackageName -NotLike "*SecHealthUI*" }}
$counter = 0
foreach ($appx in $appxProvisionedPackages)
{
Expand Down
2 changes: 1 addition & 1 deletion functions/public/Invoke-WPFMicrowin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Invoke-WPFMicrowin {
}
if (!$keepProvisionedPackages)
{
Remove-ProvisionedPackages
Remove-ProvisionedPackages -keepSecurity:$keepDefender
}

# special code, for some reason when you try to delete some inbox apps
Expand Down
23 changes: 18 additions & 5 deletions winutil.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Author : Chris Titus @christitustech
Runspace Author: @DeveloperDurp
GitHub : https://github.com/ChrisTitusTech
Version : 24.01.02
Version : 24.01.03
#>

Start-Transcript $ENV:TEMP\Winutil.log -Append
Expand All @@ -22,7 +22,7 @@ Add-Type -AssemblyName System.Windows.Forms
# Variable to sync between runspaces
$sync = [Hashtable]::Synchronized(@{})
$sync.PSScriptRoot = $PSScriptRoot
$sync.version = "24.01.02"
$sync.version = "24.01.03"
$sync.configs = @{}
$sync.ProcessRunning = $false

Expand Down Expand Up @@ -1121,8 +1121,20 @@ function Remove-Packages
Write-Progress -Activity "Removing Apps" -Status "Ready" -Completed
}

function Remove-ProvisionedPackages
function Remove-ProvisionedPackages([switch] $keepSecurity = $false)
{
<#
.SYNOPSIS
Removes AppX packages from a Windows image during MicroWin processing
.PARAMETER Name
keepSecurity - Boolean that determines whether to keep "Microsoft.SecHealthUI" (Windows Security) in the Windows image
.EXAMPLE
Remove-ProvisionedPackages -keepSecurity:$false
#>
$appxProvisionedPackages = Get-AppxProvisionedPackage -Path "$($scratchDir)" | Where-Object {
$_.PackageName -NotLike "*AppInstaller*" -AND
$_.PackageName -NotLike "*Store*" -and
Expand All @@ -1138,6 +1150,7 @@ function Remove-ProvisionedPackages

if ($?)
{
if ($keepSecurity) { $appxProvisionedPackages = $appxProvisionedPackages | Where-Object { $_.PackageName -NotLike "*SecHealthUI*" }}
$counter = 0
foreach ($appx in $appxProvisionedPackages)
{
Expand Down Expand Up @@ -2640,7 +2653,7 @@ function Invoke-WPFMicrowin {
}
if (!$keepProvisionedPackages)
{
Remove-ProvisionedPackages
Remove-ProvisionedPackages -keepSecurity:$keepDefender
}

# special code, for some reason when you try to delete some inbox apps
Expand Down Expand Up @@ -4263,7 +4276,7 @@ $inputXML = '<Window x:Class="WinUtility.MainWindow"
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" FontFamily="Segoe MDL2 Assets"
FontSize="14" Margin="16,0,0,0">&#xE721;</TextBlock>
</Grid>
<TextBlock Text="Version: 24.01.02" VerticalAlignment="Center" HorizontalAlignment="Center"
<TextBlock Text="Version: 24.01.03" VerticalAlignment="Center" HorizontalAlignment="Center"
Margin="10,0,0,0"/>
<Button Content="&#xD7;" BorderThickness="0"
BorderBrush="Transparent"
Expand Down

0 comments on commit 46fdfdf

Please sign in to comment.