Auto-populate Windows Machines in an AD using APIs

In this lesson, we would go over how to use device42 APIs to auto-populate the database for all machines in a windows Active Directory Environment using the APIs and Iron Python/powershell script.

Why Iron Python?
Well, 2 simple reasons:
1. Python is our language of choice for device42. You can substitute this language of your choice in these scripts as long as it can interact with REST APIs.
2. There is no install required, you can just drop the executables in a folder and as long as you have .NET 4 framework installed, you are good to go.


1. Install IronPython Binaries


Assuming you have Powershell and .Net 4 framework installed already, you can just download the Installer or Binaries for IronPython. I prefer binaries, because you would just need to unzip the folder and you are ready to go.

2. Download the sample script (


You can download the latest script at
Once you click on the script file, you can click on download and save that file (File>Save Page As…); preferably in same folder as binaries for IronPython are unzipped.

3. Get Sample Script ready for your environment


Edit the script and change these sections:
BASE_URL: This would be the url for device42 appliance, please make sure there is no trailing ‘/’ in the end.
Example: BASE_URL=’https://d42app.device42.pvt’

USER & PASSWORD would be credentials for an Administrator who has access to log into device42 appliance.

Just these quick changes and you are ready to run the script.

4. Running the script


From command line, go the folder where binaries for IronPython are and run ipy.exe passing the script name as the argument as highlighted in image above.

Choose Any option and script should populate the d42 database as per chosen option.

Please note that cmd.exe has to be running as domain administrator to enumerate domain objects or you have to be logged in as a domain administrator on the system you are running this from.

To run cmd.exe as domain administrator, you might need to do the following:
From command prompt, invoke cmd.exe using runas:

runas /user:domainAdministrator “cmd.exe”

Now you can cd to the IronPython directory(or use respective paths) and run ipy.exe and pass Active Directory python script as parameter as shown in image in step 4.