28 November 2012

Automate Unmounting WIM Files

This script will allow you to painlessly mount WIM files for editing. It runs relative to its location it was executed from.

Here is the link to download this script.


 '*******************************************************************************  
 '     Program: UnmountWIM.vbs  
 '      Author: Mick Pletcher  
 '        Date: 22 February 2010  
 '    Modified:  
 '  
 ' Description: This script will unmount the current mounted WIM file.  
 '              1) Define Relative Path  
 '              2) Select the WIM file  
 '              3) Mount the WIM file  
 '              4) Cleanup Global Variables  
 '*******************************************************************************  

 Option Explicit  

 REM Define Global Variables  
 DIM RelativePath : Set RelativePath = Nothing  

 DefineRelativePath()  
 UnmountWIM()  
 ImageUnmounted()  
 GlobalVariableCleanup()  

 '*******************************************************************************  

 Sub DefineRelativePath()  

      REM Get File Name with full relative path  
      RelativePath = WScript.ScriptFullName  
      REM Remove file name, leaving relative path only  
      RelativePath = Left(RelativePath, InStrRev(RelativePath, "\"))  

 End Sub  

 '*******************************************************************************  

 Sub UnmountWIM()  

      REM Define Local Objects  
      DIM oShell : SET oShell = CreateObject("Wscript.Shell")  

      REM Define Local Variables  
     'DIM Unmount    : Unmount    = Chr(34) & "C:\Program Files\Windows AIK\Tools\x86\imagex.exe" & Chr(34) & " /unmount mount /commit"  
      DIM MountDIR   : MountDIR   = Chr(32) & "/MountDir:" & RelativePath & "Mount"  
      DIM Parameters : Parameters = Chr(32) & "/commit"  
      DIM Unmount    : Unmount    = "DISM /Unmount-WIM" & MountDIR & Parameters  

      oShell.Run Unmount, 1, True  

      REM Cleanup Local Variables  
      Set MountDIR   = Nothing  
      Set oShell     = Nothing  
      Set Parameters = Nothing  
      Set Unmount    = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub ImageUnmounted()  

      REM Define Local Objects  
      DIM FSO : Set FSO = CreateObject("Scripting.FileSystemObject")  

      If NOT FSO.FolderExists(RelativePath & "Mount\Windows") Then  
           MsgBox("Image is unmounted")  
      Else  
           MsgBox("Image failed to unmount")  
      End If  

      REM Cleanup Local Objects  
      Set FSO = Nothing  

 End Sub  

 '*******************************************************************************  

 Sub GlobalVariableCleanup()  

      Set RelativePath = Nothing  

 End Sub  

Related Posts:

  • Moving a Computer to different OUs through using PowerShell scripts NOTE: You can find the new methodology and code in my later post located here.  I know there have been a lot of blogs out here showing how to move a computer to an OU, but I have taken a different approach. This is … Read More
  • TPM Readiness Verification A while back, I posted a PowerShell script that verified if the TPM was ready for BitLocker to be applied in a build. Recently, the script stopped working. I decided to decipher the code I had borrowed to make the script wor… Read More
  • Moving Computers to Designated OU during Build Process It has been four years since I published the last version of the PowerShell script to move systems from one OU to another during a build process. In that version, it required making a task sequence for each OU, which if ther… Read More
  • Google Chrome Installation One-Liner Instead of wanting to keep up with the latest Google Chrome installers, I wanted to create a one-liner that can download Chrome from the Google URI and then silently install it in the reference image build process. This one… Read More
  • Accessing MDT and SCCM Task Sequence Variables While rewriting a PowerShell automation script to move machines in Active Directory, I had been trying to pass the MachineObjectOU task sequence variable to the PowerShell script within the command line task sequence. It con… Read More

1 comments: