You are here:   Research
  |  Login

Welcome to my blog, quickest way to find articles is usually to search for them.

Minimize
Search in All Title Contents
 
     

PowerShelling around with MDT OEM Media and the Anker 13-port USB 3.0 Hub

Mar 06 2016

What to do on a Sunday morning?  Well copying a 10 GB MDT media deployment share (OEM Scenario) to 32 USB sticks for a start  :)

At first I didn’t think the actual copying would be that much faster by using a USB Hub, but boy, was I wrong. Copying to 13 USB sticks simultaneously was not too much slower than just copy to one of them. The Anker 13-port USB 3.0 Hub just rocks for copying MDT media-based deployments (many small files, like drivers etc.).

After testing a few rounds via File Explorer, it was time for automation. In this post you find the scripts the prepares the USB sticks, copies the MDT OEM media to them, and then ejects them. Now if I could only find a way for them to physically fly to the target computers too, that would be awesome :)

Ankerw800
The Anker 13-port USB 3.0 Hub connected to my laptop.

Format the USB sticks and make them active

Here is a PowerShell script to formats all connected USB sticks and make them active.

WARNING: Use at your own risk, or at least don’t blame me if the wrong disk is wiped :)

# Enumerate the USB sticks, format them with NTFS and make them active
$Disks = Get-Disk | Where-Object {$_.Path -match "USBSTOR"}

foreach ($testDisk in $Disks)
{
    Write-Output $testDisk.FriendlyName
}

Read-Host "`nThe above disks will be wiped. If this is not correct, please hit CTRL-C to cancel, or press Enter to continue...`n"

foreach ($Disk in $Disks)
{
    Write-Output "Processing Disk number: $($Disk.Number)"
    
    # Clean the disk
    Clear-Disk –InputObject $Disk -RemoveData –confirm:$False

    # Create the new partition, format with NTFS, assign drive letter and a label
    $Partition = New-Partition –InputObject $Disk -UseMaximumSize
    Format-Volume -NewFileSystemLabel "MDTMEDIA" -FileSystem NTFS -Partition $Partition –Confirm:$False
    Add-PartitionAccessPath -DiskNumber $Disk.Number -PartitionNumber 1 -AssignDriveLetter

    # Make the USB stick active
    Set-Partition -DiskNumber $Disk.Number -PartitionNumber 1 -IsActive $True
}

Copying the MDT media to the USB sticks (asynchronously)

Here is a PowerShell script that copies the MDT media to all USB sticks, asynchronously, using PowerShell background processes.

# Enumerate the USB Sticks and copy the MDT OEM Media to them (asynchronously)
$MDTMedia = "E:\MDTOEMMedia\Content\*"
$Disks = Get-Disk | Where-Object {$_.Path -match "USBSTOR"}
foreach ($Disk in $Disks)
{
    Write-Output "Processing Disk number: $($Disk.Number)"
    $Drive  = Get-Partition -DiskNumber $Disk.Number -PartitionNumber 1
    Start-Job -Scriptblock{ 
        param($MDTMedia,$Destination) 
        Copy-Item $MDTMedia $Destination -Recurse -Force
    } -ArgumentList $MDTMedia,($Drive.DriveLetter+":\")
    
    # Output job info
    Write-Output "`nWaiting for completion...`n"
    Get-Job | ? {$_.State -eq 'Complete' -and $_.HasMoreData} | % {Receive-Job $_}
    }
    while((Get-Job -State Running).count){
        Get-Job | ? {$_.State -eq 'Complete' -and $_.HasMoreData} | % {Receive-Job $_}
        start-sleep -seconds 1
    
}

Ejecting the USB sticks

Here is a PowerShell script to eject all connected USB sticks.

# Enumerate the USB Sticks and eject them
$Disks = Get-Disk | Where-Object {$_.Path -match "USBSTOR"}
foreach ($Disk in $Disks)
{
    Write-Output "Processing Disk number: $($Disk.Number)"
    $Drive  = Get-Partition -DiskNumber $Disk.Number -PartitionNumber 1
    $driveEject = New-Object -comObject Shell.Application
    $driveEject.Namespace(17).ParseName($Drive.DriveLetter+":").InvokeVerb("Eject")
}


image
PowerShell background processes copying the MDT OEM Media.








Happy deployment, and thanks for reading!


What our lawyers makes us say:

This information is provided "AS IS" with no warranties, confers no rights and is not supported by the authors or Deployment Artist.

Copyright © 2017 by Deployment Artist (the company behind deployment research). All rights reserved. No part of the information on this web site may be reproduced or posted in any form or by any means without the prior written permission of the publisher.

Shorthand: Don't pass off our work as yours, it's not nice.

Blog Archive

Minimize