-
Notifications
You must be signed in to change notification settings - Fork 0
/
Win11_24h2.ps1
175 lines (139 loc) · 6.6 KB
/
Win11_24h2.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Define the base path for all operations
$basePath = "e:\!dism"
function Get-Wim {
param (
[string]$isoFolderPath = "$basePath\iso\win1124h2",
[string]$mountPath = "$basePath\mount",
[string]$baseWimPath = "$basePath\Windows_11_24h2_Base.wim",
[string]$enterpriseWimPath = "$basePath\Windows_11_24h2_Enterprise_Base.wim"
)
# Get the first and only ISO file in the folder
$isoPath = Get-ChildItem -Path $isoFolderPath -Filter *.iso | Sort-Object LastWriteTime -Descending | Select-Object -First 1
if ($null -eq $isoPath) {
Write-Output "No ISO file found in the specified folder."
return
}
# Mount the ISO
Mount-DiskImage -ImagePath $isoPath.FullName
$diskImage = Get-DiskImage -ImagePath $isoPath.FullName
# Create mount directory if it doesn't exist
if (-Not (Test-Path $mountPath)) {
New-Item -ItemType Directory -Path $mountPath
}
# Mount the ISO to the directory
$mountResult = Mount-DiskImage -ImagePath $isoPath.FullName -PassThru | Get-Volume | Select-Object -ExpandProperty DriveLetter
$mountDrive = "$($mountResult):\"
# Copy the WIM file, overwriting if it exists
Copy-Item -Path "$mountDrive\sources\install.wim" -Destination $baseWimPath -Force
# Dismount the ISO
Dismount-DiskImage -ImagePath $isoPath.FullName
Write-Output "Base WIM file extracted to $baseWimPath"
# Get the indexes of all images in the base WIM
$images = Get-WindowsImage -ImagePath $baseWimPath
# Find the index for the Enterprise image
$enterpriseImage = $images | Where-Object { $_.ImageName -eq "Windows 11 Enterprise" }
if ($null -eq $enterpriseImage) {
Write-Output "Enterprise image not found in the base WIM."
return
}
# Export the Enterprise image to a new WIM file
Export-WindowsImage -SourceImagePath $baseWimPath -SourceIndex $enterpriseImage.ImageIndex -DestinationImagePath $enterpriseWimPath -DestinationName "Windows 11 Enterprise 24H2" -ScratchDirectory $mountPath -CheckIntegrity
Write-Output "Enterprise WIM file exported to $enterpriseWimPath"
}
function Get-WimPackages {
param (
[string]$enterpriseWimPath = "$basePath\Windows_11_24h2_Enterprise_Base.wim",
[string]$wimMountPath = "$basePath\mount",
[string]$packagesOutputPath = "$basePath\win1124h2_packages_base.txt"
)
# Create mount directory if it doesn't exist
if (-Not (Test-Path $wimMountPath)) {
New-Item -ItemType Directory -Path $wimMountPath
}
# Mount the Enterprise WIM file
Mount-WindowsImage -ImagePath $enterpriseWimPath -Path $wimMountPath -Index 1
# Get all provisioned packages
$packages = Get-AppxProvisionedPackage -Path $wimMountPath
# Export the list of provisioned packages to a text file (DisplayName only)
$packages | Select-Object DisplayName | Format-Table -AutoSize | Out-String | Set-Content -Path $packagesOutputPath -Force
# Dismount the WIM
Dismount-WindowsImage -Path $wimMountPath -Discard
Write-Output "Provisioned packages list exported to $packagesOutputPath"
}
function New-Wim {
param (
[string]$enterpriseWimPath = "$basePath\Windows_11_24h2_Enterprise_Base.wim",
[string]$testWimPath = "$basePath\Windows_11_24h2_Test.wim",
[string]$wimMountPath = "$basePath\mount",
[string]$scratchDir = "$basePath\scratch",
[string]$imageName = "Windows 11 Enterprise 24H2",
[string]$packagesOutputPath = "$basePath\win1124h2_packages_modified.txt"
)
# Get the indexes of all images in the Enterprise WIM
$images = Get-WindowsImage -ImagePath $enterpriseWimPath
# Find the index for the Enterprise image
$enterpriseImage = $images | Where-Object { $_.ImageName -like "*Enterprise*" }
if ($null -eq $enterpriseImage) {
Write-Output "Enterprise image not found in the Enterprise WIM."
return
}
# Mount the Enterprise image
$wimMountPath = "$basePath\mount"
if (-Not (Test-Path $wimMountPath)) {
New-Item -ItemType Directory -Path $wimMountPath
}
Mount-WindowsImage -ImagePath $enterpriseWimPath -Path $wimMountPath -Index $enterpriseImage.ImageIndex
# Get all provisioned packages
$packages = Get-AppxProvisionedPackage -Path $wimMountPath
# Create an array of whitelisted apps
$whitelistedApps = @(
"Microsoft.ApplicationCompatibilityEnhancements",
"Microsoft.AV1VideoExtension",
"Microsoft.AVCEncoderVideoExtension",
"Microsoft.DesktopAppInstaller",
"Microsoft.GetHelp",
"Microsoft.HEIFImageExtension",
"Microsoft.HEVCVideoExtension",
"Microsoft.MPEG2VideoExtension",
"Microsoft.RawImageExtension",
"Microsoft.ScreenSketch",
"Microsoft.SecHealthUI",
"Microsoft.StorePurchaseApp",
"Microsoft.Todos",
"Microsoft.VP9VideoExtensions",
"Microsoft.WebMediaExtensions",
"Microsoft.WebpImageExtension",
"Microsoft.Windows.Photos",
"Microsoft.WindowsAlarms",
"Microsoft.WindowsCalculator",
"Microsoft.WindowsCamera",
"Microsoft.WindowsNotepad",
"Microsoft.WindowsSoundRecorder",
"Microsoft.WindowsStore",
"Microsoft.WindowsTerminal",
"MicrosoftWindows.Client.WebExperience"
)
# Loop through all provisioned packages and remove the ones not in the whitelist
foreach ($package in $packages) {
if ($whitelistedApps -contains $package.DisplayName) {
Write-Output "Whitelisted package: $($package.DisplayName)"
} else {
Write-Output "Removing package: $($package.DisplayName)"
Remove-AppxProvisionedPackage -Path $wimMountPath -PackageName $package.PackageName -Verbose
}
}
# Get all provisioned packages
$packages = Get-AppxProvisionedPackage -Path $wimMountPath
# Export the list of provisioned packages to a text file (DisplayName only)
$packages | Select-Object DisplayName | Format-Table -AutoSize | Out-String | Set-Content -Path $packagesOutputPath -Force
# Dismount, save, and check the integrity of the WIM
Dismount-WindowsImage -Path $wimMountPath -Save -CheckIntegrity
Write-Output "Enterprise image modified and saved."
# Export the Enterprise image to a new WIM file
Export-WindowsImage -SourceImagePath $enterpriseWimPath -SourceIndex $enterpriseImage.ImageIndex -DestinationImagePath $testWimPath -DestinationName $imageName -ScratchDirectory $scratchDir -CheckIntegrity
Write-Output "Enterprise image exported to $testWimPath with name '$imageName'"
}
# Example usage
Get-Wim
#Get-WimPackages
New-Wim