MDT Powershell module inside WinPE
-
Thursday, January 17, 2013 3:56 AM
Hi guys,
I'm looking to fully automate my image creation process. I'm trying to run a Powershell task at the end of the capture TS that will perform two things:
- Import the new image as an OS
- Create a TS based on a template I created
I have the logic worked out and I can run the commands manually on the server after the capture process and its successful. However I'm having a real problem getting the MicrosoftDeploymentToolkit.psd1 module loaded into the WinPE.
I've created a folder for the module, copied the module itself out of the MDT %INSTALLDIR%\bin\ folder along with Microsoft.BDD.PSSnapIn*.* and then added that to the WinPE 'Extra folder to add' section in the MDT Console.
I've added a simple pause in my TS right at the end so I can run the commands manually to test
I can load the ZTIUtility module fine and can access all the MDT variables I need, but when I run the following I encounter an error:
- Import-Module X:\ZTIUtility\ZTIUtility.psd1
- Import-Module X:\MicrosoftDeploymentToolkit\MicrosoftDeploymentToolkit.psd1 (so far so good)
- New-PSDrive -Name "DS001" -PSProvider MDTProvider -Root "\\server\Deployment$"
I end up with an error stating:
"Could not load file or assembly 'Microsoft.BDD.Core'..."
and the PSDrive is never created.
Has anyone been successful in loading the MDT module into the PE or am I going about this all wrong
- Edited by mhouston100 Thursday, January 17, 2013 3:59 AM
All Replies
-
Thursday, January 17, 2013 4:16 AMSorry, also had included the Microsoft.BDD.Core*.* files from the bin folder
-
Thursday, January 17, 2013 3:23 PM
I like the idea... I came up with two ways you might do it:
1. Instead of trying to do it from WinPE at the end of the Capture Task Sequence, why not boot back into the Full OS? If you've already captured it and you are doing this in a Virtual Machine that you'll Revert, should be no harm done. Then you could actually install the MDT Workbench as an Application (give you all the required dependencies) and then run your PowerShell with the benefit of a full OS + the locally loaded MDT Workbench.
2. The second idea depends on if you are using Hyper-V to manage your VMs for image capture. If you are, you could set up something automatic like what I blogged about (http://dcthegeek.blogspot.com/2013/01/automating-image-building-with-mdt.html) for starting your capture. I know that if I trigger mine at 12:30 AM, it's always done by 2:30 AM. Knowing that, you could create a Task Scheduler entry on the Host at 3 (or even 3:30 AM just to be sure) that runs your "import" PowerShell and then the entire thing would be automated end-to-end. [This also assumes that MDT workbench is installed on your Hyper-V Host]
I like the idea of auto-importing captured images... I'll have to look more into doing the same. : )
David Coulter | http://DCtheGeek.blogspot.com | @DCtheGeek
-
Thursday, January 17, 2013 8:25 PM
Unfortunately we are using VirtualBox on our workstations... but I'm checking out your blog anyway, can never have too much knowledge!
I'm swayed to the idea of restarting the VM into the full OS and installing MDT. I considered it at first but dismissed it as unnecessary, but now I'm thinking it might be the easiest was to do it, but also to manage it as well.
The reason behind this is that I'm the only one here with any real experience with MDT or deployment and rather then have to train the other guys on the WHOLE system, if I can just automate as much as possible then they cant start to use it more efficiently, rather then request a new image from me, they can just do it themselves. With this they can simply boot a VM to the network and then let it go!
So I'll be testing today adding the following at the end of the task sequence:
- ...
- Gather local Only
- Create WIM
- *extra* Run a restart
- *extra* Install MDT as an Application
- *extra* Run custom PowerShell script
- End task sequence
Thanks for the response, I'll post back the results.
-
Thursday, January 17, 2013 8:59 PMJust as a note, remember that if you are using Windows 8, Hyper-V is now available (instead of Virtual PC). I looked for scripting options for VirtualBox, but everything I found was "Linux only". Hyper-V is very well supported with PowerShell, it may make your job easier to switch. I, too, used to use VirtualBox, but I'm very happy I switched to Hyper-V, and even more so with the v3 updated in Windows 8 / Server 2012.
David Coulter | http://DCtheGeek.blogspot.com | @DCtheGeek
-
Thursday, January 17, 2013 9:01 PMI was actually just using Hyper-V as I just converted my workstation to Windows 8, I loved everything about it except the fact that it doesn't have a boot menu, unfortunately for me that was a deal breaker when working with MDT.
-
Thursday, January 17, 2013 9:16 PMYeah, I've missed the "press spacebar to boot from ISO" window a few times because of the time the Virtual Machine Connection takes on VM startup. Normally if you reboot it again once it's established, you'll see it and be able to hit the spacebar to make it load MDT. The other thing I do, especially in my automated builds, is make sure the VHD/VHDX is blank with nothing on it. In that event, it will always boot to your CD and run your MDT Boot Image (assuming that's what is attached).
David Coulter | http://DCtheGeek.blogspot.com | @DCtheGeek
-
Thursday, January 17, 2013 10:38 PM
We use a WDS server for network booting, but I didn't consider just generating the ISO locally and using that, you may have just solved another issue for me!
I've just tested the process I laid out above and it doesn't seem to work. Once the WIM capture is completed, it will restart, but it still restarts into the WinPE. Obviously the TS task to install the app then fail's, which causes the PE to reboot, which then boots back into the PE etc etc etc.
You wouldn't happen to know what process runs after the TS to clean up the WinPE? If I manually run the LTICleanup it seems to boot back into Windows afterwards but obviously that will then delete all the scripts etc not sure if the other steps will then run?
-
Thursday, January 17, 2013 10:52 PMI don't know if WinPE needs to be cleaned up per se, but you may need to run a script to update BCD and change the order back to windows (from WinPE being the default), which should get you back into full Windows and allow you to install MDT and run the PowerShell.
David Coulter | http://DCtheGeek.blogspot.com | @DCtheGeek
-
Thursday, January 17, 2013 11:00 PMI think that would def be easier... I get the feeling that running the cleanup will break any TS functionality.
-
Friday, January 18, 2013 3:29 AM
Not looking good though. Just got a chance to test it.
So what I followed was:
- ...
- Gather Local
- Create WIM
- Pause TS with message box (just a simple PS script)
- Run BCDEdit /delete {current}
- Reboot
- Install Application Microsoft Deployment Toolkit 2012
- Pause TS (to test powershell commands to add image and TS)
- Reboot
Seemed to be working great! Removing the BCD entry caused it to reboot into Windows but that's where the trouble started:
- It takes about 10 minutes to get back into Windows as it has to go through the whole 'first start' stage - Finding and installing devices, setting up desktop etc. I think this might be a deal breaker as it takes to long anyway. Would be quicker to just run the script form the server or workstation.
- When it finally does get into the OS it reports that a script is missing (I didn't note it down cause I was an idiot and impatient) but whatever was missing it stopped the TS from continuing.
I think I need to revisit my original theory of getting the MDT module working in the PE environment, I could see it working in that case!
- Edited by mhouston100 Friday, January 18, 2013 3:29 AM
-
Friday, January 18, 2013 4:22 AM
The actual error was :
Can not find script filce "C:\LTIBootstrap.vbs"
-
Friday, January 18, 2013 5:23 AMI'd still lean back toward doing it on the Host via a script afterwards, either by Task Scheduler or otherwise. You could build something that watches your capture folder (monitor) and when a new files is added, starts the import into MDT via PowerShell.
David Coulter | http://DCtheGeek.blogspot.com | @DCtheGeek
-
Sunday, January 20, 2013 8:11 PM
I was just considering that last night... I think that would be the best way, just run it on the MDT host (which is actually the WDS host as well). Probably something along the line of:
- Check Capture folder
- Import captures one at a time
- Create task sequence based on capture name
- Move captures to another backup folder (if even required).
This servers the double purpose of importing them and cleaning them up.
I'll be working on it today so I'll post back here with results! I can see this streamlining the work of deploy / capture quite a bit for the other guys here.
- Edited by mhouston100 Sunday, January 20, 2013 8:12 PM
-
Tuesday, January 29, 2013 10:37 PM
So for anyone that is interested I have created a PS script that can be run from a users MDT workstation.
A few caveats as it is pretty specific to our environment:
- My TS in the capture share are WIN7 and WIN8
- I've created a custom TS template called "WIN7 Template.xml"
- The image name / computer name is generated as (TS)(date).wim
Probably some other things I have forgotten but this is the script I use now:
## Variables $depserver = "server" #replace with your server ## Import the required modules for dealing with MDT deployment shares Import-Module "C:\Program Files\Microsoft Deployment Toolkit\Bin\MicrosoftDeploymentToolkit.psd1" New-PSDrive -Name "DS001" -PSProvider MDTProvider -Root "\\$depserver\Deployment$" # List each file in the 'captures' directory dir "\\$depserver\Deployment$\Captures" | foreach-object { $sourcefile = $_.fullname $basefile = $_.basename $taskseq = $basefile.substring(0,4) #Import the OS into MDT import-mdtoperatingsystem -path "DS001:\Operating Systems" -SourceFile $sourcefile -DestinationFolder $basefile -Verbose #Create a new task sequence based on the operating system imported IF ($taskseq -eq "WIN7") { import-mdttasksequence -path "DS001:\Task Sequences\Windows 7" -Name "$basefile" -Template "WIN7 Template.xml" -Comments "Insert a description here." -ID "$basefile" -Version "1.0" -OperatingSystemPath "DS001:\Operating Systems\WIN7CDrive in $basefile $_" -FullName "CharlesB" -OrgName "Company" -HomePage "http://www.google.com.au" -AdminPassword "password" -Verbose -ErrorAction Continue move-item -path $sourcefile -Destination "\\$depserver\deployment$\capturebackup\" } IF ($taskseq -eq "WIN8") { import-mdttasksequence -path "DS001:\Task Sequences\Windows 8" -Name "$basefile" -Template "WIN7 Template.xml" -Comments "Insert a description here." -ID "$basefile" -Version "1.0" -OperatingSystemPath "DS001:\Operating Systems\WIN8CDrive in $basefile $_" -FullName "CharlesB" -OrgName "Company" -HomePage "http://www.google.com.au" -AdminPassword "password" -Verbose -ErrorAction Continue move-item -path $sourcefile -Destination "\\$depserver\deployment$\capturebackup\" } } # Update the deployment share update-MDTDeploymentShare -path "DS001:" –Verbose # Clean up remove-psdrive "DS001" Remove-Module MicrosoftDeploymentToolkitSo the technician can just:
- Boot to the network in a VM
- Select WIN7 or WIN8
- Wait for capture to work
- Run the above script
And done...
At the moment it copies the old capture images to another location but once we go live I'll just be deleting them.
- Edited by mhouston100 Tuesday, January 29, 2013 10:38 PM
- Marked As Answer by mhouston100 Tuesday, January 29, 2013 10:43 PM

