Skip to content

Commit

Permalink
Continue conversion (part 2)
Browse files Browse the repository at this point in the history
Finished part 2 of DISM command to cmdlet conversion
  • Loading branch information
CodingWonders committed Mar 31, 2024
1 parent 98dbe8e commit 0b63967
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
32 changes: 19 additions & 13 deletions functions/private/Invoke-MicroWin-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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*" }}
Expand All @@ -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 <installation media>\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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions functions/public/Invoke-WPFMicrowin.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
39 changes: 22 additions & 17 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.03.30
Version : 24.03.31
#>
param (
[switch]$Debug,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
{
Expand All @@ -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*" }}
Expand All @@ -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 <installation media>\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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 0b63967

Please sign in to comment.