Setting a Static IP Address during a Deployment via PowerShell and ConfigMgr 2012

This week my blog post will be about setting a static IP address during a deployment. I’m going to do this via a combination of a PowerShell script, a computer variable and a task sequence. I know it is possible in the Task Sequence Wizard to supply static IP information, but there are two reason why I did not use that solution:

  1. I’ve seen a lot of situations where the IP configuration got applied after the policy requests were done to the Management Point. This would cause the task sequence to fail.
  2. I wanted a zero touch experience for the persons performing the deployment.

PowerShell Script

Let’s start with the most important part of my solution, a PowerShell script. This script sets a static IP address with, a subnet, a gateway and two DNS servers. It needs an IP address as input and needs to be adjusted per situation, as I hardcoded my subnet, gateway and DNS servers in the call of the function. It can be easily adjusted to need more input variables for a subnet, a gateway and two DNS servers. The variable names tell the story of which number is needed when.

param ( [string]$strIPAddress ) function Set-StaticIPAddress ($strIPAddress, $strSubnet, $strGateway, $strDNSServer1, $strDNSServer2) { $NetworkConfig = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "IpEnabled = 'True'" $NetworkConfig.EnableStatic($strIPAddress, $strSubnet) $NetworkConfig.SetGateways($strGateway, 1) $NetworkConfig.SetDNSServerSearchOrder(@($strDNSServer1, $strDNSServer2)) } Set-StaticIPAddress $strIPAddress "255.255.255.0" "192.168.137.1" "192.168.137.100" "192.168.137.101"

Task Sequence

SetStaIPAddNow add the PowerShell script to an old-school Package, so it will be available for a task sequence. Then create a standard Install an existing image package task sequence. Now edit the task sequence and make sure the following step is included:

  • Add a step Run PowerShell Script with the following settings:
    • Package: <NameOfPackageThatContainsStaticIPScript>
    • Script name: <NameOfTheStaticIPScript>
    • Parameters: %IPAddress%
      • Note: IPAddress is the computer variable that I use to set the IP address for a device.
    • PowerShell execution policy: Bypass

Computer Variable

CompVariJust a small note about the specified computer variable. There are multiple way’s of adding this variable. One way is creating the variable by hand via the nice sun/star-shaped button, another way is creating a small addition for my Import Computer Information Form.

6 thoughts on “Setting a Static IP Address during a Deployment via PowerShell and ConfigMgr 2012

  1. Hi Peter,

    is it also possible to extend the script with multiple variables? Now you run the PowerShell script with one variable (%IPAddress%).

    It should be nice if we can also put the gateway and DNS servers into variables.

    Regards,
    Mark

Leave a Comment