Browse Tag: wds

MDT – Get Computer Name from PHP Script

The Microsoft Deployment Toolkit (MDT) is a tool that can be used to assist in the deployment of the Microsoft Windows operating system. It is usually used in conjunction with Windows Deployment Services (WDS) for enterprise image deployment via PXE (network booting). MDT is very customizable, allowing it to be adapted to suit many different environments.

In this post, I will be discussing how to use an MDT web service to get the computer name (Called the OSDComputerName in MDT) from a PHP script. This logic can be applied to many other MDT fields, but in this example I will be using the OSDComputerName. Many people who might manage smaller deployments may ask why this is useful, especially when MDT can use serial numbers and other things in the computer name. I would answer that every company is different in their computer naming convention. The ability to hand off the computer naming to PHP makes it very flexible. PHP can query databases and integrate with asset management systems to get the name for the computer being imaged. This flexibility really helps to speed up the deployment process for larger organisations.

Now that the introduction is out the way, let’s get in to it! The first step is to setup your PHP script. For this, I used an IIS web server. In the example below, I have left the section blank where you need to determine the computer name. I have included the relevant code to get the IP address of the client, should you need that for your script. You can use any logic here such as connecting to databases, using APIs or querying active directory. Also note the headers that are in place. This is because we need to return an XML file with the computer name for MDT to parse.

<?php
//set the script to output XML
header('Content-Type: text/xml');
$output = '<?xml version="1.0" encoding="utf-8" ?>';
//get the IP address of the device being imaged
$ip = $_SERVER['REMOTE_ADDR'];
//do some magic here to determine the computer name. Put it in the $computername variable
//return the computer name
$output = $output.'<string xmlns="http://myiisserver.mydomain/myscript.php">'.$computername.'</string>';
print ($output);
?>

This script must be available over HTTP to the clients being imaged. You can test the script output by visiting the page in your web browser.

Step two is to add the web service settings to MDT. For this, we need to edit the CustomSettings.ini file in the deployment share (in the control folder). For this, I usually use Notepad++ which is a fantastic, free text editor although you could just as easily use Notepad. Add the following lines to your CustomSettings file. You need to replace the web service location to the URL of your script. Once again, make sure that this is available to your clients being imaged. If you are using a DNS name, make sure that the clients will be able to resolve the name.

[GetComputerName]
WebService=http://myiisserver.mydomain/myscript.php
OSDComputerName=string

The above code tells MDT that this section of the file will be using a web service. It queries the web service and assigns the result to the OSDComputerName variable. If you do not choose to skip the computer name screen in the light touch wizard then the calculated computer name will be shown in the computer name box in the wizard.

That’s it! You will need to update your deployment share, then image a PC and try it out!