December 7 2011

Set custom SCCM task sequence variable to client DHCP server

I had a requirement to be able set a custom SCCM Task Sequence variable to the value (IP address) of the DHCP server that had issued the IP address to the client . This meant that later in the Task Sequence I could re-use this value for other things, in this case it was to map a network drive, eg \%DHCP_Server%temp. I used a VB script to set this:

' Purpose: Set SCCM task sequence variable 'DHCP_Server' to the value of the DHCP server IP address
' Date: 06/12/2011
' Version: 1.0

strComputer = "."

' Create Task Sequence environment object
dim osd: set env = CreateObject("Microsoft.SMS.TSEnvironment")

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

' Find active network adapter
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1

For Each objAdapter in colAdapters

' Set variable in the Operating System Deployment environment
env("DHCP_Server") = objAdapter.DHCPServer

n = n + 1
Next

When you dump out the Task Sequence variables, you can then see it at the top of the list:

DHCP_Server=10.0.0.1
SMSTSDisableWow64Redirection=false
P0000012=file:VOL001:sources
WorkingDirectory=s:
_SMSMediaGuid=2BB82B7E-0BE0-48D7-9AC2-3DE93F726D71
_SMSTSAdvertID=P00200F6
_SMSTSBootImageID=P000005F
_SMSTSBootMediaPackageID=P0000012
_SMSTSBootMediaSourceVersion=2
…….
…….
…….
…….



----------------------------------------------------------------------------
I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.

----------------------------------------------------------------------------


Tags: , , , , ,

Posted December 7, 2011 by danovich in category "Scripting", "SMS / SCCM

Leave a Reply