Run DiscoverNow from a script using multiple IP addresses
In ServiceNow Product Documentation, the following article, Run DiscoverNow from a Script, describes the basic process of running DiscoverNow from a script. However, customers who are required to run this script and also require the ability to enter multiple IP addresses, are unable to get the process to work correctly.
When reviewing the code, we noticed that all of the variables were defined globally, so we suggest that the code be encapsulated in a function. This resolves the issue.
When using short variables such as d (as seen in the following script example), and defining the variable globally, it is very easy for the variable to be overwritten if another script is also using a globally defined variable called d, elsewhere on the system. Encapsulating the code within a function fences off the variables, which are defined locally and can not be re-defined outside of that function.
The next section provides an example for customers who may require the same functionality.