Setting a Static IP during SCCM Task Sequence

Recently I had to build a Task Sequence for computer which will eventually be outside of the domain and out of the main site – no GPO’s, no DHCP no nothing!

I’m accustomed to configure pretty much everything using GPO’s and others means and I have to say it’s all pretty easy once the machine is a member of the domain. Things like Start Menu options and links, Desktop wallpaper and even Computers IP configuration is pretty easy when you have the proper tools like GPO, DHCP and etc. In this case, I had to write pretty much everything using scripts and since the machine I’m deploying is Windows 7, most of the scripts are written in VBScript and not PowerShell.

I’m going to write several posts documenting most of the stuff I did during the TS. The first post was already published a few days ago Easiest way to add Multi_SZ reg key.

So lets start with how do I set the static IP address.

My task sequence starts with a basic HTA file that prompts the end user for basically 2 parameters:

The name of the machine he would like to set

The IP address he would like to use.

Once the user enters those value they are stored in variables which are later access by the VBScript which sets the IP address using netsh command. Why not use PowerShell you ask? Well because Windows 7 does not recognize the PowerShell cmdlets that set the IP address. They are only available to Windows 8

One the most painful things about netsh is the fact you have to supply the adapter name or index. To get the exact name of the adapter I have used WMI.

strComputer = "."

Set sWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set NetAdapterCaption = sWMI.ExecQuery _

& ("Select caption from Win32_NetworkAdapterConfiguration where ipenabled='true'")

Set NetConnectionID = sWMI.ExecQuery _

& ("Select NetConnectionID from Win32_NetworkAdapter where caption='" & NetAdapterCaption.itemindex(0).caption & "'")


My next step is to access the variables which were set during the HTA:

Set oTaskSequence = CreateObject("Microsoft.SMS.TSEnvironment")

sIPAddr = oTaskSequence("OSDAdapter0IPAddressList")

sGWAddr = oTaskSequence("OSDAdapter0Gateways")


Now that I have all the variables set I can go ahead and configure the static ip address using netsh:

Set sh = CreateObject("Wscript.Shell") "netsh interface ipv4 set address name=""" & NetConnectionID.itemindex(0).NetConnectionID & """ static " & sIPAddr & " " & sGWAddr & " 1", 0, True

sh.Run "netsh interface ipv4 set dnsservers name=""" & NetConnectionID.itemindex(0).NetConnectionID & """ static primary", 0, True

What do you think about this post?