diff --git a/functions/private/Invoke-MicroWin-Helper.ps1 b/functions/private/Invoke-MicroWin-Helper.ps1 index a7937d43b7..f34adb3513 100644 --- a/functions/private/Invoke-MicroWin-Helper.ps1 +++ b/functions/private/Invoke-MicroWin-Helper.ps1 @@ -54,8 +54,6 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender Remove-Features -keepDefender:$false #> - #$featlist = dism /English /image:$scratchDir /Get-Features | Select-String -Pattern "Feature Name : " -CaseSensitive -SimpleMatch - #$featlist = $featlist -split "Feature Name : " | Where-Object {$_} $featlist = (Get-WindowsOptionalFeature -Path $scratchDir).FeatureName if ($dumpFeatures) { @@ -66,7 +64,9 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender $_ -NotLike "*Printing*" -AND $_ -NotLike "*TelnetClient*" -AND $_ -NotLike "*PowerShell*" -AND - $_ -NotLike "*NetFx*" + $_ -NotLike "*NetFx*" -AND + $_ -NotLike "*Media*" -AND + $_ -NotLike "*NFS*" } if ($keepDefender) { $featlist = $featlist | Where-Object { $_ -NotLike "*Defender*" }} @@ -76,17 +76,17 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender $status = "Removing feature $feature" Write-Progress -Activity "Removing features" -Status $status -PercentComplete ($counter++/$featlist.Count*100) Write-Debug "Removing feature $feature" - # dism /image:$scratchDir /Disable-Feature /FeatureName:$feature /Remove /NoRestart > $null + Disable-WindowsOptionalFeature -Path "$scratchDir" -FeatureName $feature -Remove -ErrorAction SilentlyContinue -NoRestart } Write-Progress -Activity "Removing features" -Status "Ready" -Completed + Write-Host "You can re-enable the disabled features at any time, using either Windows Update or the SxS folder in \Sources." } function Remove-Packages { - $appxlist = dism /English /Image:$scratchDir /Get-Packages | Select-String -Pattern "Package Identity : " -CaseSensitive -SimpleMatch - $appxlist = $appxlist -split "Package Identity : " | Where-Object {$_} + $pkglist = (Get-WindowsPackage -Path "$scratchDir").PackageName - $appxlist = $appxlist | Where-Object { + $pkglist = $pkglist | Where-Object { $_ -NotLike "*ApplicationModel*" -AND $_ -NotLike "*indows-Client-LanguagePack*" -AND $_ -NotLike "*LanguageFeatures-Basic*" -AND @@ -124,11 +124,18 @@ function Remove-Packages $_ -NotLike "*UI.XaML*" } - foreach ($appx in $appxlist) + foreach ($pkg in $pkglist) { - $status = "Removing $appx" - Write-Progress -Activity "Removing Apps" -Status $status -PercentComplete ($counter++/$appxlist.Count*100) - dism /English /image:$scratchDir /Remove-Package /PackageName:$appx /NoRestart + try { + $status = "Removing $pkg" + Write-Progress -Activity "Removing Apps" -Status $status -PercentComplete ($counter++/$pkglist.Count*100) + Remove-WindowsPackage -Path "$scratchDir" -PackageName $pkg -NoRestart -ErrorAction SilentlyContinue + } + catch { + # This can happen if the package that is being removed is a permanent one, like FodMetadata + Write-Host "Could not remove OS package $($pkg)" + continue + } } Write-Progress -Activity "Removing Apps" -Status "Ready" -Completed } @@ -168,8 +175,7 @@ function Remove-ProvisionedPackages([switch] $keepSecurity = $false) { $status = "Removing Provisioned $($appx.PackageName)" Write-Progress -Activity "Removing Provisioned Apps" -Status $status -PercentComplete ($counter++/$appxProvisionedPackages.Count*100) - #dism /English /image:$scratchDir /Remove-ProvisionedAppxPackage /PackageName:$($appx.PackageName) /NoRestart - Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $appx.PackageName + Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $appx.PackageName -ErrorAction SilentlyContinue } Write-Progress -Activity "Removing Provisioned Apps" -Status "Ready" -Completed } diff --git a/functions/public/Invoke-WPFMicrowin.ps1 b/functions/public/Invoke-WPFMicrowin.ps1 index f5d9a04a8c..89d15872bb 100644 --- a/functions/public/Invoke-WPFMicrowin.ps1 +++ b/functions/public/Invoke-WPFMicrowin.ps1 @@ -117,7 +117,6 @@ public class PowerManagement { if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - #dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host Add-WindowsDriver -Path "$scratchDir" -Recurse -Driver "$driverPath" } else @@ -336,7 +335,7 @@ public class PowerManagement { if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host + Add-WindowsDriver -Path "$scratchDir" -Driver "$driverPath" -Recurse } else { diff --git a/winutil.ps1 b/winutil.ps1 index 674bc85be3..38b3bf1c77 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -10,7 +10,7 @@ Author : Chris Titus @christitustech Runspace Author: @DeveloperDurp GitHub : https://github.com/ChrisTitusTech - Version : 24.03.30 + Version : 24.03.31 #> param ( [switch]$Debug, @@ -47,7 +47,7 @@ Add-Type -AssemblyName System.Windows.Forms # Variable to sync between runspaces $sync = [Hashtable]::Synchronized(@{}) $sync.PSScriptRoot = $PSScriptRoot -$sync.version = "24.03.30" +$sync.version = "24.03.31" $sync.configs = @{} $sync.ProcessRunning = $false @@ -850,8 +850,6 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender Remove-Features -keepDefender:$false #> - #$featlist = dism /English /image:$scratchDir /Get-Features | Select-String -Pattern "Feature Name : " -CaseSensitive -SimpleMatch - #$featlist = $featlist -split "Feature Name : " | Where-Object {$_} $featlist = (Get-WindowsOptionalFeature -Path $scratchDir).FeatureName if ($dumpFeatures) { @@ -862,7 +860,9 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender $_ -NotLike "*Printing*" -AND $_ -NotLike "*TelnetClient*" -AND $_ -NotLike "*PowerShell*" -AND - $_ -NotLike "*NetFx*" + $_ -NotLike "*NetFx*" -AND + $_ -NotLike "*Media*" -AND + $_ -NotLike "*NFS*" } if ($keepDefender) { $featlist = $featlist | Where-Object { $_ -NotLike "*Defender*" }} @@ -872,17 +872,17 @@ function Remove-Features([switch] $dumpFeatures = $false, [switch] $keepDefender $status = "Removing feature $feature" Write-Progress -Activity "Removing features" -Status $status -PercentComplete ($counter++/$featlist.Count*100) Write-Debug "Removing feature $feature" - # dism /image:$scratchDir /Disable-Feature /FeatureName:$feature /Remove /NoRestart > $null + Disable-WindowsOptionalFeature -Path "$scratchDir" -FeatureName $feature -Remove -ErrorAction SilentlyContinue -NoRestart } Write-Progress -Activity "Removing features" -Status "Ready" -Completed + Write-Host "You can re-enable the disabled features at any time, using either Windows Update or the SxS folder in \Sources." } function Remove-Packages { - $appxlist = dism /English /Image:$scratchDir /Get-Packages | Select-String -Pattern "Package Identity : " -CaseSensitive -SimpleMatch - $appxlist = $appxlist -split "Package Identity : " | Where-Object {$_} + $pkglist = (Get-WindowsPackage -Path "$scratchDir").PackageName - $appxlist = $appxlist | Where-Object { + $pkglist = $pkglist | Where-Object { $_ -NotLike "*ApplicationModel*" -AND $_ -NotLike "*indows-Client-LanguagePack*" -AND $_ -NotLike "*LanguageFeatures-Basic*" -AND @@ -920,11 +920,18 @@ function Remove-Packages $_ -NotLike "*UI.XaML*" } - foreach ($appx in $appxlist) + foreach ($pkg in $pkglist) { - $status = "Removing $appx" - Write-Progress -Activity "Removing Apps" -Status $status -PercentComplete ($counter++/$appxlist.Count*100) - dism /English /image:$scratchDir /Remove-Package /PackageName:$appx /NoRestart + try { + $status = "Removing $pkg" + Write-Progress -Activity "Removing Apps" -Status $status -PercentComplete ($counter++/$pkglist.Count*100) + Remove-WindowsPackage -Path "$scratchDir" -PackageName $pkg -NoRestart -ErrorAction SilentlyContinue + } + catch { + # This can happen if the package that is being removed is a permanent one, like FodMetadata + Write-Host "Could not remove OS package $($pkg)" + continue + } } Write-Progress -Activity "Removing Apps" -Status "Ready" -Completed } @@ -964,8 +971,7 @@ function Remove-ProvisionedPackages([switch] $keepSecurity = $false) { $status = "Removing Provisioned $($appx.PackageName)" Write-Progress -Activity "Removing Provisioned Apps" -Status $status -PercentComplete ($counter++/$appxProvisionedPackages.Count*100) - #dism /English /image:$scratchDir /Remove-ProvisionedAppxPackage /PackageName:$($appx.PackageName) /NoRestart - Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $appx.PackageName + Remove-AppxProvisionedPackage -Path $scratchDir -PackageName $appx.PackageName -ErrorAction SilentlyContinue } Write-Progress -Activity "Removing Provisioned Apps" -Status "Ready" -Completed } @@ -3696,7 +3702,6 @@ public class PowerManagement { if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - #dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host Add-WindowsDriver -Path "$scratchDir" -Recurse -Driver "$driverPath" } else @@ -3915,7 +3920,7 @@ public class PowerManagement { if (Test-Path $driverPath) { Write-Host "Adding Windows Drivers image($scratchDir) drivers($driverPath) " - dism /English /image:$scratchDir /add-driver /driver:$driverPath /recurse | Out-Host + Add-WindowsDriver -Path "$scratchDir" -Driver "$driverPath" -Recurse } else {