-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathUpdateWIM.ps1
More file actions
81 lines (64 loc) · 2.32 KB
/
UpdateWIM.ps1
File metadata and controls
81 lines (64 loc) · 2.32 KB
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
Clear-Host
$Global:MountPath
$Global:RelativePath
$Global:WimFile
$Global:UpdatesPath
Function GetRelativePath{
$Global:RelativePath=(split-path $SCRIPT:MyInvocation.MyCommand.Path -parent)+"\"
Write-Host $Global:RelativePath
}
Function GetWimFile{
$FileName = Get-ChildItem $Global:RelativePath | Where-Object {($_.Name -like "*.wim")}
$Global:WimFile = $Global:RelativePath+$FileName
Write-Host $Global:WimFile
}
Function MountWIM{
$Global:MountPath = $Global:RelativePath+"Mount\"
If ((Test-Path $Global:MountPath) -ne $true){
New-Item -ItemType directory -Path $Global:RelativePath"Mount"
}
Write-Host $Global:MountPath
$Arguments = "dism.exe /mount-wim /wimfile:"+$Global:WimFile+[char]32+"/index:1 /mountdir:"+$Global:MountPath
Write-Host $Arguments
Invoke-Expression -Command $Arguments
}
Function UnmountWIM{
$Arguments = "dism.exe /unmount-wim /mountdir:"+$Global:MountPath+[char]32+"/commit"
Write-Host $Arguments
Invoke-Expression -Command $Arguments
}
Function CleanupWIM{
$Arguments = "dism.exe /cleanup-wim"
Write-Host $Arguments
Invoke-Expression -Command $Arguments
}
Function GlobalMemoryCleanup{
Clear-Variable -Name MountPath -Scope Global -Force
Clear-Variable -Name WimFile -Scope Global -Force
Clear-Variable -Name UpdatesPath -Scope Global -Force
Clear-Variable -Name RelativePath -Scope Global -Force
Remove-Variable -Name MountPath -Scope Global -Force
Remove-Variable -Name WimFile -Scope Global -Force
Remove-Variable -Name UpdatesPath -Scope Global -Force
Remove-Variable -Name RelativePath -Scope Global -Force
}
GetRelativePath
GetWimFile
MountWIM
$Global:UpdatesPath = $Global:RelativePath+"*.msu"
$UpdatesArray = Get-Item $Global:UpdatesPath
ForEach ($Updates in $UpdatesArray) {
$Arguments = "dism.exe /image:"+$Global:MountPath+[char]32+"/Add-Package /PackagePath:"+$Updates
Write-Host $Arguments
Invoke-Expression -Command $Arguments
Start-Sleep -Seconds 10
}
UnmountWIM
CleanupWIM
Clear-Variable -Name Arguments -Scope Local -Force
Clear-Variable -Name Updates -Scope Local -Force
Clear-Variable -Name UpdatesArray -Scope Local -Force
Remove-Variable -Name Arguments -Scope Local -Force
Remove-Variable -Name Updates -Scope Local -Force
Remove-Variable -Name UpdatesArray -Scope Local -Force
GlobalMemoryCleanup