Skip to content

Instantly share code, notes, and snippets.

@realslacker
Created January 30, 2018 18:58
Show Gist options
  • Save realslacker/e3ff5408255f49cbbc57ab5e89c8391d to your computer and use it in GitHub Desktop.
Save realslacker/e3ff5408255f49cbbc57ab5e89c8391d to your computer and use it in GitHub Desktop.
Push a LayoutModification.xml file into a WIM prior to installation.
<#
.SYNOPSIS
Update the Start Menu layout in a WIM file
.DESCRIPTION
Update the Start Menu layout in a WIM file
.PARAMETER Path
The path to the WIM image file (typically install.wim)
.PARAMETER LayoutModification
The path to the Start Layout created by running:
Export-StartLayout -Path C:\LayoutModification.xml
.PARAMETER PassThru
.EXAMPLE
.\Update-StartLayoutInWim.ps1 -Wim C:\Install.wim -Layout C:\LayoutModification.xml
#>
[CmdletBinding(SupportsShouldProcess=$true)]
param (
[Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true)]
[string[]]
$Path,
[Parameter(Mandatory=$true, Position=2)]
[string]
$LayoutModification,
[Parameter(Mandatory=$false)]
[int]
$Index=1,
[switch]
$PassThru
)
begin {
$LayoutModification = Get-Item -Path $LayoutModification `
-ErrorAction Stop
$StartDate = Get-Date
$TempDirectory = New-Item -Path "$env:TEMP\$($StartDate.ToString('yyyyMMddHHmmss'))" `
-ItemType Directory
Write-Verbose "Start Time: $StartDate"
Write-Verbose "Temporary Directory: $TempDirectory"
}
process {
foreach ( $Item in $Path ) {
$Item = Get-Item -Path $Item -ErrorAction Stop
Write-Host "Updating 'LayoutModification.xml' in '$($Item.FullName)'..." -ForegroundColor Yellow
Write-Host "Mounting Windows Image"
Mount-WindowsImage -Path $TempDirectory `
-ImagePath $Item `
-Index $Index
Write-Host "Updating Start Layout"
Copy-Item -Path $LayoutModification `
-Destination "$TempDirectory\Users\Default\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" `
-Force `
-Confirm:$false
Write-Host "Dismounting Windows Image"
Dismount-WindowsImage -Path $TempDirectory `
-Save `
-CheckIntegrity
if ( $PassThru.IsPresent ) {
Get-Item -Path $Item
}
}
}
end {
Write-Host "Cleaning Up Environment"
$TempDirectory | Remove-Item -Recurse `
-Force `
-Confirm:$false `
> $null
Write-Verbose "End Time: $((Get-Date).ToString())"
}
@WileC
Copy link

WileC commented Jun 25, 2020

Hello,

The example line might be:
.\Update-StartLayoutInWim.ps1 -Path C:\Install.wim -LayoutModification C:\LayoutModification.xml

Is there a way, to update all indexes in a wim-file? In my wim-files there's index 1 "Windows Home", index 2 "Windows Education" and index 3 "Windows Pro" ... and so on.

I would like to update all LayoutModifications in all wim indexes..

Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment