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.
- Iron Python, available here: https://ironpython.codeplex.com/releases/view/62475
- .Net 4 framework, available here: https://www.microsoft.com/download/en/details.aspx?id=17851
- PowerShell. v1.0 or 2.0(preferred)
- Device42 sample scripts, latest version available here(under src folder): https://github.com/device42/Device42-API
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 (ad-sample.py)
You can download the latest script at https://github.com/device42/Device42-API/tree/master/src.
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.
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.