Tuesday, 5 April 2011

Import drivers into MDT maintaining folder structure

I recently got an email from Johan Arwidmark's mailing list at Truesec, this mail contained a powershell script to import drivers into MDT whilst maintaining the folder structure, this will allow multiple driver imports for a range of hardware without dumping all of the drivers in on huge lump in the 'Out Of Box Drivers' folder.


The Drivers folder layout will follow the format as follows

Drivers\
     |------OS 1\
     |          |--------->Manufacturer1\
     |          |                   |----------->Model1\
     |          |                   |----------->Model2\
     |          |--------->Manufacturer2\
     |                              |----------->Model1\
     |                              |----------->Model2\
     |------OS 2\
                |--------->Manufacturer1\
                |                   |----------->Model1\
                |                   |----------->Model2\
                |--------->Manufacturer2\
                                   |----------->Model1\
                                   |----------->Model2\



     
You will need to edit the first three lines of this script to match your environment, otherwise it should be good to go.


$DriverStore = "C:\Drivers"
$MDTDSRoot = "C:\MDTBuildLab"
$PSDriveName = "DS001"

Add-PSSnapIn Microsoft.BDD.PSSnapIn
New-PSDrive -Name "$PSDriveName" -PSProvider MDTProvider -Root $MDTDSRoot
# Proces each of the operating systems folders
Get-ChildItem "$DriverStore" | foreach {

    # Display the folder we are processing
    Write-Host "Processing $($_.FullName)" -ForeGroundColor green;Write-Host ""

    # Create the operating system folder in the MDT 2010 Deployment Workbench
    new-item -path $PSDriveName":\Out-of-Box Drivers" -enable "True" -Name "$($_.Name)" -ItemType "folder" -Verbose

    # Process each of the vendor folders
    $OSFolder = $_
    Get-ChildItem $_.FullName | foreach {
       
        # Display the folder we are processing
        Write-Host "Processing $($_.FullName)" -ForeGroundColor green;Write-Host "" 

        # Create the vendor folder in the MDT 2010 Deployment Workbench
        new-item -path $PSDriveName":\Out-of-Box Drivers\$OSFolder" -enable "True" -Name "$($_.Name)" -ItemType "folder" -Verbose
       
       # Process each of the model folders
       $VendorFolder = $_
       Get-ChildItem $_.FullName | foreach {

            # Display the folder we are processing
            Write-Host "";Write-Host "Processing $($_.FullName)" -ForeGroundColor green;Write-Host "" 
   
           # Create the model folder in the MDT 2010 Deployment Workbench
           new-item -path $PSDriveName":\Out-of-Box Drivers\$OSFolder\$VendorFolder" -enable "True" -Name "$($_.Name)" -ItemType "folder" -Verbose

           # Import the drivers into MDT 2010 Deployment Workbench
           Import-MDTDriver -Path $PSDriveName":\Out-of-Box Drivers\$OSFolder\$VendorFolder\$($_.Name)" -SourcePath "$($_.FullName)" -Verbose
          }
    } 
}

During testing of this script I encountered errors while creating folders, this error appears to be down to the code using  '-enable "True"' powershell spits this out with some ugly red lettering, I have found that by removing this part of the code the script appears to run perfectly and populate MDT as we hope.

No comments:

Post a Comment

Please enter your comment here, all comments are subject to moderation