Apply IP Configuration from a Database
I am currently deploying 64 Citrix XenApp servers with Altiris. The deployment consists of an OS Image, OS Configuration and finally Citrix XenApp and Applications.
In the OS Configuration part the IP configuration needs to be applied and I decided to do this with a database.
The database consists of 2 tables; one table with the per host settings and one table with the global settings (such as DNS).
In the Altiris job both tables are read from an embedded VBScript and assigned to the NIC.
Database configuration
I created a database (SQL Server) called IPManagement with 2 tables:
The globalconfig table has a name and a data field:
And contains only the DNS settings:
The hostconfig table has fields for hostname, ip address, netmask and default gateway:
Some sample data:
Altiris Configuration
In Altiris I have added the database as a custom data source, this can be done via Tools | Options | Custom Data Sources:
The Script:
The final step is the VBScript, which use the Custom Token feature to retreive the data from the database:
'Set Network Configuration
'vbscript
IPAddress=Array(Trim(" %#IPManagement*"select ip from hostconfig where hostname='%NODEFULL%'"% "))
NetMask=Array(Trim(" %#IPManagement*"select mask from hostconfig where hostname='%NODEFULL%'"% "))
Gateway=Array(Trim(" %#IPManagement*"select gateway from hostconfig where hostname='%NODEFULL%'"% "))
DNS=Array(Trim(" %#IPManagement*"select data from globalconfig where name='dns1'"% "), Trim(" %#IPManagement*"select data from globalconfig where name='dns2'"% "))
Metric = Array(1)
strComputer = "."
Set objWMIService = GetObject("winmgmts:\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = True",,48)
For Each objItem in colItems
If Left(objItem.IPAddress(0), 6) = "10.250" Then
WScript.Echo("Found Adapter, current adres is: " & objItem.IPAddress(0) & " Desired Address is: " & IPAddress(0))
Ret = objItem.EnableStatic(IPAddress, NetMask)
WScript.Echo("EnableStatic returned: " & Ret)
If Ret = 0 Then
Ret = objItem.SetGateWays(Gateway, Metric)
WScript.Echo("SetGateWays returned: " & Ret)
Ret = objItem.SetDNSServerSearchOrder(DNS)
WScript.Echo("SetDNSServerSearchOrder returned: " & Ret)
End If
End If
Next
WScript.Quit(Ret)
Note that I had to do a little trick using the Trim statement and a space to get a correct assignment to the variables. Without the space Altiris doesn’t properly recognize the custom token.
The array is necessary beasue the EnableStatic and SetGateways Methods require array parameters even when there’s just a single entry.
Was once an enthusiastic PepperByte employee but is now working elsewhere. His blogs are still valuable to us and we hope to you too.