«

»

Jul 07 2013

Bulk import computers into the MDT Database using PowerShell

The story of every admins life; arrive in the morning and find out that new computers need to be deployed and the existing ones upgraded. So you start preparing the images and import them in MDT; you are using MDT, right ? If not you should start, because is an awesome free tool. On side of this makes you happy, because you get rid of those old OS’s, but the other side gives you a little head-each because MDT has a small problem when it comes to computer names. You either walk trough the wizard and type the computer name by hand during deployment, or configure an MDT database and populate it with computer names. I know you are thinking right now…but Adrian ! both of this methods need a lot of typing. Not necessarily, because there is a PowerShell module from Michael Niehaus (MDTDB.zip) that can populate the database with computer names, mac addresses and everything.

After you downloaded the module, unzip the MDTDB.psm1 file somewhere on your MDT server then open PowerShell and view the server current execution policy using the Get-ExecutionPolicy command. If it sais Restricted, you need to change that, in order for the script to run.

To change the execution policy, type:

Now is time to import the module in PowerShell using the Import-Module command. I put -Verbose at the end so I can see all the details.

In order to manipulate the database, we first need to connect to it. Issue the following command:

in my case is:

I removed the instance parameter because I’m using the default SQL instance. If you don’t get any errors, it means the connection was successful.

All that is left now is to add and a computer into the database. This is done by using the New-MDTComputer command followed by its parameters:

The above example will create a single entry in MDT with the same description and computer name of WSK001. Off course you need to replace the mac address and the UUID with valid ones.

   

For more options and parameters you can always use the Get-Help command.

Populating computers by using the above example is still going to take you a lot of time. Think of it, for every workstation and server you need to create a line like that. It will be much easier to have a computer list with their mac addresses and names, and import that list into the database. This is what I’m going to show you next, but first let’s do that list. Open Excel and create something similar like you see in the bellow image; just replace the letters and numbers with your own.

When you’re done save it as CSV.



In order for the script to work we need to put the computers list in a variable (computers) using the following command:

You know that it worked, because if you type the variable name and press Enter, all the computers on the .csv file should be listed.

We are now ready to populate the database with the computers list from the .csv file we just created. You can paste the command in PowerShell or save it as script and run it.

If you now take a look in the Computers folder in MDT, all the computers from the .csv file should be listed here.

You might have to close and re-open the MDT console to see the results.

   

Most of the times you are not going to need the UUID in order to successfully finish a deployment, the MAC address is enough.

What do you do to get the MAC address ? export the DHCP list into a file, then use that data.

You might need more settings populated in the Details tab of a computer entry like organization name, administrator password or product key. All you need to do is modify the script and add the settings you want.

After the import was successful, you can issue the Get-MDTComputer command to list all the computers in the MDT database.

If for some reason you need to remove computers, you can always use the Remove-MDTComputer command followed by the entry ID.

Learn to use this, and it will ease you life, your deployment life.

Want content like this delivered right to your

email inbox?


1 comment

  1. Liam Connors

    I have an issue with this script i keep getting an error saying “Missing expression after ‘&’ in the pipeline element” I am very limited with powershell and I can’t troubleshoot what’s wrong with it. Could you possibly help me out?

    For ($i=1; $i -le $computers.count; $i++)
    {
    New-MDTComputer -macAddress $computers[$i-1].mac -uuid $computers[$i-1].UUID -description $computers[$i-1].name -settings @{
    OSInstall='YES';
    OSDComputerName=$computers[$i-1].name;
    OrgName='vKernel Technology';
    ProductKey='xxxx-xxxx-xxxx-xxxx';
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

css.php