function Remove-WimShortNames { [CmdletBinding()] param( [Parameter( Mandatory )] [string] $WimFile, [string] $MountDirectory = 'C:\mnt', [ValidateSet( 'Errors', 'Warnings', 'WarningsInfo' )] [string] $LogLevel = 'Errors', [string] $PsExecPath = "$env:ProgramFiles\SysinternalsSuite\PsExec.exe" ); if( -not [System.IO.File]::Exists( $WimFile ) ) { throw "File '$WimFile' does not exist."; } if( -not [System.IO.File]::Exists( $PsExecPath ) ) { throw "File '$PsExecPath' does not exist."; } $params = @{ LogLevel = $LogLevel; }; mkdir -Path $MountDirectory -ErrorAction 'SilentlyContinue' | Out-Null; Get-WindowsImage -ImagePath $WimFile @params | ForEach-Object -Process { "Now processing edition '{0}'. Mounting to '{1}'." -f $_.ImageName, $MountDirectory | Write-Host; Mount-WindowsImage -Path $MountDirectory -ImagePath $WimFile -Name $_.ImageName @params; & $PsExecPath -s "$env:windir\system32\fsutil.exe" 8dot3name strip /f /s $MountDirectory; if( $LASTEXITCODE ) { throw "fsutil.exe exited with error code $LASTEXITCODE."; } Dismount-WindowsImage -Path $MountDirectory -Save @params; }; Remove-Item -LiteralPath $MountDirectory -Force; }