How to automatically unpack MOC and Base VHDs archives using PowerShell

 

As trainers I consider that we spend a disproportional amount of time to prepare the classrooms for our classes.

Any new course is a new challenge.

Estimated 8h classroom setup ends in more than 2 days for the first time (ex 10750A, 10751A…)
So any automation that can save time will give us more free time to prepare our courses or spend with friends.

One of the activities that consumes a lot of time is unpacking the downloaded course archives.

The annoying thing is that we need to introduce confirmation after starting each unpack action.

In most cases running more unrar action in parallel will not make the whole action to finish earlier.

So I looked for a solution to make this action simpler.

From various solution found on the net I picked up a script from Classroom Setup Tools v1.1 – http://pscst.codeplex.com – by Ingo Karstein (http://ikarstein.wordpress.com) (all his credits reserved)

 

I made my own customizations and now I have 2 version: Unpack MOC V1a and Unpack MOC V1b

After Ver1a script you will find Ver1b script.

 

Unpack MOC V1a

 

In Ver1a we use a folder in which we temporarily move the downloaded archives.

After unpack operation we move the folders back in the initial location.

 

The Ver1a of script for course 10748 will look like this:

 

################################################################################################################################################

# Unpack MOC V1a#

# Automatically unpack(unrar) MOC downloaded courses files

#

# No list of folders used, just move folders with archived files to a defined source folder#

# Make folder $SourcePath1 (Moc Archives) on the volume ($SourceDriveLetter1)  as temporary work folder

# MANUALY move the MOC archives to be unpacked to the $SourcePath1 (Moc Archives) folder

# After finishing unpacking MANUALY move archives to the original locations

# Destination folders are set to the MOC default location

#

# Used variables:

# $Course = Number of the course (NO version included – ex:10748 and not 10748A or 10748B, etc)

# $DestDriveLetter1 = Volume for Course VM’s

# $SourcePath1 = Path of the folder where the MOC downloaded files are located

# $DestPath2 = Destination folder where the unpacked MOC files will be located

# $UnrarPath = Location of the unrar.exe file – need to be downloaded

# Download unrarw32.exe from http://www.rarlab.com/rar/unrarw32.exe and extract unrar.exe to the $UnrarPath folder

#

# Done by Florin Nicolescu –MCT  florin@learningsolution.ro ;   www.learningsolution.rowww.cursurimicrosoft.com

# Based on a script from Classroom Setup Tools v1.1 – http://pscst.codeplex.com – by Ingo Karstein (http://ikarstein.wordpress.com)

#

#################################################################################################################################################

$Course = “10748”

$DestDriveLetter1 = “c”

$SourceDriveLetter1 = “i”

$DestPath1 = -join ($DestDriveLetter1,”:\Program Files\Microsoft Learning”)

$SourcePath1 = -join ($SourceDriveLetter1,”:\Moc Archives”)

$UnrarPath = -join ($DestDriveLetter1,”:\Program Files\Microsoft Learning”)

$DestPath2 = -join ($DestDriveLetter1,”:\Program Files\Microsoft Learning\”,$Course,”\Drives”)

md $DestPath2

Set-Location $DestPath2

get-childitem -path $SourcePath1 -recurse -filter “*.exe” | % {foreach-object {start-process -Wait “$UnrarPath\unrar.exe” -ArgumentList (“x”, “-o+”, “-y”, “””$($_.FullName)”””) -RedirectStandardOutput (Join-Path $DestPath2 ($_.Name + “.log”)) -windowstyle minimized }}

################################################################################################################################################

 

 

Unpack MOC V1b

 

In Ver1B we use a list of source folders that contain the MOC and base files to be unpacked.

Depending of type of folder MOC, Base or Mid-tier Base the destination folders will be different in the list.

All you need is to edit the list in the script with the new folders locations.

If you want to skip a location in the list (example a base vhd already exists) you can mask it as comment with a # at the beginning of the row.

Pay attention that the last row in the list should not have a ( , comma) after it.

If it has it will report an error a not execute correctly.

My recommendation is to put on top of the list the folders that you might want to skip (comment) and the course folders at the end.

This will lower the probability of adding  a # (comment) for  the last line in the list, have now a comma at the end of the list and receive an error.

After finishing, if you runed the powershell script in an already opened administrator powershell window, you will see the start and finish time of the script so you can estimate the action for future use.

You need to download unrarw32.exe from http://www.rarlab.com/rar/unrarw32.exe and extract unrar.exe to $UnrarPath  folder as described in scripts.

During running the scrip  unrar will stay minimized and will not display any info if maximized (due to -windowstyle minimized switch)

All the info including the eula and unrar results will be in the course root folder.

After reading the eula (so we don’t break any agreement) and unrar results you can delete the logs (optionaly)

If a script ends with “ all ok” operation ended correctly.

 

The Ver1b of the script for course 10747 will look like this:

 

################################################################################################################################################

# Unpack MOC V1b

#

# Automatically unpack(unrar) MOC downloaded course files and aditional Base VHD’s from a list of folders

#

# You NEED TO EDIT this file to introduce the list of folders containing the downloaded archives ($DownloadedPath and in paragraph – $list… @{source …)

# Destination folders are set to the MOC default location

# You can separatelly customize location of the MOC files and of the Base VHD’s ( $DestDriveLetter1 + $DestPath2 ; $DestDriveLetter2 + $DestPath3)

#

# Used variables:

# $Course = Number of the course (no version included – ex:10747 and not 10747A or 10747B, etc)

# $DestDriveLetter1 = Volume for Course VM’s

# $DestDriveLetter2 = Volume for Base VHD’s

# $list = manualy edited(updated) list of folders containing archived folders to be unpacked

# $DestPath1 = Default root folder for MOC course and BASE folders

# $DestPath2 = Destination folder where the unpacked MOC files will be located

# $DestPath3 = Destination folder where the unpacked Base VHD’s files will be located

# $DestPath4 = Destination folder where the unpacked Mid-Tier Base VHD’s files will be located

# $UnrarPath = Location of the unrar.exe file – need to be downloaded

# Download unrarw32.exe from http://www.rarlab.com/rar/unrarw32.exe and extract unrar.exe to $UnrarPath

#

# Done by Florin Nicolescu –MCT  florin@learningsolution.ro ;   www.learningsolution.rowww.cursurimicrosoft.com

# Based on a script from Classroom Setup Tools v1.1 – http://pscst.codeplex.com – by Ingo Karstein (http://ikarstein.wordpress.com)

#

################################################################################################################################################

$Course = “10747”

$DestDriveLetter1 = “c”

$DestDriveLetter2 = “c”

$DestPath1 = -join ($DestDriveLetter1,”:\Program Files\Microsoft Learning”)

$DestPath2 = -join ($DestDriveLetter1,”:\Program Files\Microsoft Learning\”,$Course,”\Drives”)

$DestPath3 = -join ($DestDriveLetter2,”:\Program Files\Microsoft Learning\Base”)

$DestPath4 = -join ($DestPath3,”\Drives”)

$UnrarPath = -join ($DestDriveLetter1,”:\Program Files\Microsoft Learning”)

# START EDIT List (the list of folders containing the archives)

$list = @(

# Start EDIT (the list of folders containing the archives)

@{source = “I:\MOC Downloads\Base\MT12\MT12-CM-NYC-DC1”; dest = $DestPath4},

@{source = “I:\MOC Downloads\Base\MT12\MT12-CM-NYC-CFG”; dest = “$DestPath4”},

@{source = “I:\MOC Downloads\Base\MT12\MT12-CM-NYC-SVR1”; dest = “$DestPath4”},

@{source = “I:\MOC Downloads\Base\MT12\MT12-CM-NYC-SVR2”; dest = “$DestPath4”},

@{source = “I:\MOC Downloads\Base\Base10C-W7-HV”; dest = “$DestPath3”},

@{source = “I:\MOC Downloads\Base\Base11A-WS08R2SP1”; dest = “$DestPath3”},

@{source = “I:\MOC Downloads\MOC_ConfigMgr2012\10747A- Part 2 – Virtual Machines – Administering System Center 2012 Configuration Manager”; dest = $DestPath2}

# End EDIT List (the list of folders containing the archives)

)

$list | % {

Write-Host “”

$source= $_.source

$dest = $_.dest

if(!(Test-Path $dest)) {

mkdir $dest

}

Write-Host “Source: $($source)”

Write-Host ” Dest: $($dest)”

Set-Location $dest

Get-ChildItem -Path $source -Filter “*.exe” | % {

Write-Host “`t$([DateTime]::Now)”

Write-Host “`t$($_.FullName)”

Start-Process -Wait “$UnrarPath\unrar.exe” -ArgumentList (“x”, “-o+”, “-y”, “””$($_.FullName)”””) -RedirectStandardOutput (Join-Path $DestPath2 ($_.Name + “.log”)) -windowstyle minimized }

Write-Host “`t$([DateTime]::Now)”

}

####################################################################################################################################################

 

Feel free to use the scripts and improve them.

 

Live is too short, don’t waist it on classroom setups!

 

Florin Nicolescu

MCT

florin@learningsolution.ro

www.learningsolution.ro

www.cursurimicrosoft.com

Tagged

Leave a Reply