PowershellPosted by Thomas Petersen Mon, February 18, 2013 16:38:59The main goal here is to automate patching of .wim files for Windows client/server installation, to save the initial updating after installing.

When updating your image, the installation will be running quite a lot faster, than if you would have to make the install, and then start patching - no rocket science here...

Usually there would be a few different images, so the menu will be based on the current .wim files located in the image directory.

Basically the files are read into an array, and an option for choosing all images and one for abotring is added.

So the menu part of the script looks like the following:

clear-host

#location of .wim files. Being read into the $wimfiles array

$wimfiles=Get-ChildItem c:\scripts *.wim

function ToArray

# typecasting single object to array

{

begin

{

$output = @();

}

process

{

$output += $_;

}

end

{

return ,$output;

}

}

#building menu

$i=0

Write-output "Please choose image(s) to update"

do {

write-host $i $wimfiles[$i].name

$i++

} while ($i -lt ($wimfiles.count))

write-host $i 'All images'

write-host ($i+1) 'Abort'

#read choice, and validate against number of files+2 (#files, All files, Abort)

do {$WimID = Read-host "Choice"}

while ((0..($wimfiles.count+1)) -notcontains $WimID)

if ($WimID -eq ($wimfiles.count+1)) {

write-output "Aborting..."

exit

}

elseif ($WimID -eq ($wimfiles.count)) {

# All wimfiles chosen, read files into $WimPatch array

$WimPatch = Get-ChildItem c:\scripts *.wim

}

Else {

# Single file chosen, read into $WimPatch and call function ToArray, to typecast the single file to an array

$WimPatch = Get-ChildItem c:\scripts $WimFiles[$WimID].Name | ToArray

}

write-host *******************

write-host "Image(s) to be updated:"

write-host

$i=0

do {

write-host $WimPatch[$i].Name

$i++

} while ($i -lt ($WimPatch.count))

#now we have chosen which file(s) to work on, and they are ready to be sent to the patch function

About me and the blog.

Name's Thomas, I have been working with Microsoft servers since the good old NT days, and the purpose of this blog is simply to save a few scripts for future use, and hopefully help other pepole with similar tasks.Feel free to comment