Windows Updates DISM automated Script

To apply updates to an offline install.wim

Powershell script:

$UpdatesPath = “C:\temp\WIMDISM\W2K8\*\*”
$MountPath = “C:\temp\WIMDISM\MOUNTDISM”
$WimFile = “C:\temp\WIMDISM\install.wim”

Dism.exe /Mount-Wim /WimFile:$WimFile /index:1 /Mountdir:$MountPath
$UpdateArray = Get-Item $UpdatesPath
ForEach ($Updates in $UpdateArray)
{
Dism.exe /image:$MountPath /Add-Package /Packagepath:$Updates
Start-Sleep –s 3
}
Write-Host “Updates Applied to WIM”
Start-Sleep –s 10
Dism.exe /Unmount-Wim /Mountdir:$MountPath /commit
Start-Sleep –s 10
Dism.exe /Cleanup-Wim

 Update 07-06-2014 Improved script!

 

$UpdatesPath = “C:\temp\WIMDISM\W2K8\*\*”
$UpdatesPath1 = “C:\temp\WIMDISM\W2K8\*\*\*”
$MountPath = “C:\temp\WIMDISM\MOUNTDISM”
$WimFile = “C:\temp\WIMDISM\install.wim”
$temppath = “C:\temp\WIMDISM\Temp”
$ItemUpdatesPath = Get-ChildItem -file $UpdatesPath
$ItemUpdatesPath1 = Get-ChildItem -file $UpdatesPath1
$UpdateArray = $ItemUpdatesPath, $ItemUpdatesPath1
ForEach ($Updates in $UpdateArray)
{
Copy $Updates $temppath
}
Write-Host “All files copied to Temp dir”
Start-Sleep –s 10

Dism.exe /Mount-Wim /WimFile:$WimFile /index:1 /Mountdir:$MountPath
Write-Host “WIM Mounted”
Start-Sleep –s 10

Dism.exe /image:$MountPath /Add-Package /Packagepath:$temppath
Start-Sleep –s 10
Write-Host “Updates Applied to WIM”
Dism.exe /Unmount-Wim /Mountdir:$MountPath /commit
Dism.exe /Cleanup-Wim

Write-Host “Saved and Cleaned up WIM”
Start-Sleep –s 10
Del C:\temp\WIMDISM\Temp\*
Write-Host “Deleted Temp files”
Write-Host “Done”

 

If you have Image X on your laptop(or get it with GetWaikTools!) use could use the following command to compress the image

<path>\imagex.exe /compress maximum /export <path>\install.wim 1 <path>\export.wim

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s