locked
Boot from Media and static IP script RRS feed

  • General discussion

  • I thought I would give back a bit to the community.  My current engagement has a client where 2/3 of the computers are not on DHCP, and probably won't be anytime soon.  There is a feature deficiency in the SCCM boot from media function, it lets you set the IP address in the initial WinPE startup, but that address isn't communicated to Windows.  Windows comes up expecting to find DHCP.  Hint, hint here anyone from the product group, this should be added to the Apply Network Settings task :)

    This script needs to be put in the task sequence right before the Apply Network Settings task sequence step.  The script will check to see if the variables were already set in Windows (which works correctly).  If not (only happens when you are doing a new install) it will read the entries from WinPE and write them to the TS variables needed by Apply Network Settings. 

    There is a limitation to the scipt that it can only put in as much as can be entered by WinPE.  So things like multiple DNS servers for example can't be entered into PE, so they can't be transfered to Windows.

    Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")
    WQL = "Select * from Win32_NetworkAdapterConfiguration where IPEnabled = TRUE"
    Set colNetAdapters = objWMIService.ExecQuery (WQL)

    WScript.Echo "Number of adapters is " & colNetAdapters.Count

    set objSCCM = CreateObject("Microsoft.SMS.TSEnvironment")

    if objSCCM("OSDAdapter0IPAddressList") = "" then

     For Each objNetAdapter In colNetAdapters
      if objNetAdapter.DHCPEnabled then
       WScript.Echo "DHCP Enabled"
      else
       WScript.Echo "DHCP Disabled"
       objSCCM("OSDAdapter0EnableDHCP") = false
       
       if Not IsNull (objNetAdapter.IPAddress) then
        strIPAddress = objNetAdapter.IPAddress(0)
        WScript.Echo "IP Address:       " & strIPAddress
        objSCCM("OSDAdapter0IPAddressList") = strIPAddress
       end if
         
       if Not IsNull (objNetAdapter.IPSubnet) then
        strIPSubnet = objNetAdapter.IPSubnet(0)
        WScript.Echo "IP Subnet:        " & strIPSubnet
        objSCCM("OSDAdapter0SubnetMask") = strIPSubnet
       end if
         
       if Not IsNull (objNetAdapter.DefaultIPGateway) then
        strIPGateway = objNetAdapter.DefaultIPGateway(0)
        WScript.Echo "IP Gateway:       " & strIPGateway
        objSCCM("OSDAdapter0Gateways") = strIPGateway
       end if
         
       if Not IsNull (objNetAdapter.DNSServerSearchOrder) then
        strDNSServerSearchOrder = objNetAdapter.DNSServerSearchOrder(0)
        WScript.Echo "DNS Server:       " & strDNSServerSearchOrder
        objSCCM("OSDAdapter0DNSServerList") = strDNSServerSearchOrder
       end if

       if Not IsNull (objNetAdapter.MACAddress) then
        strMACAddress = objNetAdapter.MACAddress(0)
        WScript.Echo "MAC Address:      " & strMACAddress
       end if
         
       if Not IsNull (objNetAdapter.DNSDomainSuffixSearchOrder) then
        strDNSDomainSuffixSearchOrder = objNetAdapter.DNSDomainSuffixSearchOrder(0)
        WScript.Echo "DNS DOMAIN:       " & strDNSDomainSuffixSearchOrder
       end if
       
       if Not IsNull (objNetAdapter.WINSPrimaryServer) then
        strWins = objNetAdapter.WINSPrimaryServer
        objSCCM("OSDAdapter0EnableWINS") = true
        if Not IsNull (objNetAdapter.WINSSecondaryServer) then
         strWins = strWins & "," & objNetAdapter.WINSSecondaryServer
        end if
        WSCript.Echo "WINS Server:      " & strWins
        objSCCM("OSDAdapter0WINSServerList") = strWins
       else
        objSCCM("OSDAdapter0EnableWINS") = false
       end if

       objSCCM("OSDAdapterCount") = 1
          
      end if
     Next
    End If


    Bob
    Thursday, May 26, 2011 12:44 PM

All replies

  • MDT 2010 has the option to set static IP in Winpe
    Thursday, May 26, 2011 3:31 PM
  • That's true but we aren't using MDT.  The customer I'm at couldn't begin to support MDT after we left.  Besides there is very little in MDT that we need, SCCM provides just about everything we need. 


    Bob
    Thursday, May 26, 2011 3:47 PM
  • Hi Bob, thank you very much for providing this script.  I have been looking for something like this for some time.

    However I seem to have an issue with it.  I put this script right before the apply network settings task sequence and it appears as if the script and the apply network settings run successfully without error.  However upon system reboot the IP information is gone.  I have no idea how to troubleshoot this as there is no error in the smsts.log file regarding either of the above steps.

    Monday, August 22, 2011 8:53 PM
  • Not sure why it wouldn't work.  Here's a script I put together to do a quick dump to check what the variables are doing.

    Dim sVar

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

    For Each sVar in osdv4.GetVariables()
     WScript.Echo "Variable " & sVar & ":" & osdv4(sVar)
    Next

    run it from the command prompt F8 before minisetup kicks in.

    cscript GetVars.vbs > c:\dump.txt

    This thing outputs a lot of stuff, so make sure you dump to a file and you don't use wscript.

     


    Bob
    Monday, August 22, 2011 11:53 PM
  • Hi Bob.

     

    I ran that little script you gave me, but I'm a little unclear about what you mean by minisetup?  I ran that getvars script right after the Apply Network Settings, which obviously is before the system reboot.  Here are some pertinent parts of that dump.txt:

    Variable OSDAdapter0DNSServerList:XX.XX.XX.XX
    Variable OSDAdapter0EnableDHCP:False
    Variable OSDAdapter0Gateways:XX.XX.XX.X
    Variable OSDAdapter0IPAddressList:XX.XX.XX.XX
    Variable OSDAdapter0SubnetMask:XX.XX.XX.XX
    Variable OSDAdapterCount:0

    All of the DNS and IP information is correct so before the reboot, it looks like the OSD variables have been assigned, but aren't surviving the reboot.

    The OSDAdapterCount:0 is concerning to me however.

    Is there other parts of the dump that I could provide you that might help?

    Just for giggles, I ran the script immediately after the first reboot as soon as I could bring the F8 command prompt up and it tells me that ActiveX component can't create object: 'Microsoft.SMS.TSEnvironment'. It is finishing up the Setup Windows and ConfigMgr task sequence at that point.

    Just for more info, here is the order of the task sequence around the OSD Variables script:

    Apply Device Drivers
    Your OSD Variable Script
    Apply Network Settings
    Setup Windows and ConfigMgr. 

    I really really appreciate the help so far.  I feel like I am so close here to getting over this hump.

     

     

     



    Wednesday, August 24, 2011 7:10 PM
  • Mini setup is when Windows does the actual setup using the info in the image and the task sequence. 

    OSDAdapterCount set to zero tells me that you might not have an identified network adapter.  Quick check, at the F8 command prompt, do an IPCONFIG and see if you have a network connection.  If you don't that generally means the cable is unplugged or WinPE doesn't have the driver it needs and you need to add it.  If you haven't added a driver to WinPE, I always work from another copy of the WIM, or at least make a backup.  When you add a driver you have to add all of the drivers that you need and the ones that were already there.  SCCM can show you what's already there.


    Bob
    Thursday, August 25, 2011 1:11 PM
  • Bob,

    Thanks so much for the reply.  So minisetup is prior to the first reboot?  If so, then my dump was done correctly.

    At the F8 command prompt before the reboot (after OS image is laid down), I have network connectivity.  From the moment I punch in the IP information at the WinPE prompt, I have network connectivity until after the first reboot.  My drivers are in order on the WinPE boot disk (we don't have PXE, rather we mount virtual media to drac/ilo.).

    I'm wondering if I can modify collection settings on the collection to set OSDadaptercount = 1 so that might override the 0.  I will give it a shot and let you know.

    Please let me know if you can think of anything else. I have been using this test box for a while so I know network connectivity is good as far as cabling and WinPE drivers.  Again, I really appreciate the help.  This is the last hump before we are done with OSD and ready to deploy in production.    

    Thursday, August 25, 2011 1:37 PM
  • Here is a new version of the script, I think it has a few tweaks in it, it's been a while.  But I don't think it will solve your problem, neither will setting the variable in the collection.  Try this, it might help, run the script as cscript StaticIPBoot and look at the output, it might give you some clue as to what's going on, or better yet change the script in the task sequence to:

    cscript StaticIPBoot.vbs > c:\ip.txt

    The script is fairly verbose, it might give you an idea of why it's not working.  The only reason I can see for that variable to be zero is that the script isn't finding any network adapters, or DHCP is enabled.

    Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")
    WQL = "Select * from Win32_NetworkAdapterConfiguration where IPEnabled = TRUE"
    Set colNetAdapters = objWMIService.ExecQuery (WQL)

    WScript.Echo "Number of adapters is " & colNetAdapters.Count

    set objSCCM = CreateObject("Microsoft.SMS.TSEnvironment")

    if objSCCM("OSDAdapter0IPAddressList") = "" then

     For Each objNetAdapter In colNetAdapters
      if objNetAdapter.DHCPEnabled then
       WScript.Echo "DHCP Enabled"
      else
       WScript.Echo "DHCP Disabled"
       objSCCM("OSDAdapter0EnableDHCP") = "false"
       
       if Not IsNull (objNetAdapter.IPAddress) then
        strIPAddress = objNetAdapter.IPAddress(0)
        WScript.Echo "IP Address:       " & strIPAddress
        objSCCM("OSDAdapter0IPAddressList") = strIPAddress
       end if
         
       if Not IsNull (objNetAdapter.IPSubnet) then
        strIPSubnet = objNetAdapter.IPSubnet(0)
        WScript.Echo "IP Subnet:        " & strIPSubnet
        objSCCM("OSDAdapter0SubnetMask") = strIPSubnet
       end if
         
       if Not IsNull (objNetAdapter.DefaultIPGateway) then
        strIPGateway = objNetAdapter.DefaultIPGateway(0)
        WScript.Echo "IP Gateway:       " & strIPGateway
        objSCCM("OSDAdapter0Gateways") = strIPGateway
       end if
         
       if Not IsNull (objNetAdapter.DNSServerSearchOrder) then
        strDNSServerSearchOrder = objNetAdapter.DNSServerSearchOrder(0)
        WScript.Echo "DNS Server:       " & strDNSServerSearchOrder
        objSCCM("OSDAdapter0DNSServerList") = strDNSServerSearchOrder
       end if

       if Not IsNull (objNetAdapter.MACAddress) then
        strMACAddress = objNetAdapter.MACAddress(0)
        WScript.Echo "MAC Address:      " & strMACAddress
       end if
         
       if Not IsNull (objNetAdapter.DNSDomainSuffixSearchOrder) then
        strDNSDomainSuffixSearchOrder = objNetAdapter.DNSDomainSuffixSearchOrder(0)
        WScript.Echo "DNS DOMAIN:       " & strDNSDomainSuffixSearchOrder
       end if
       
       if Not IsNull (objNetAdapter.WINSPrimaryServer) then
        strWins = objNetAdapter.WINSPrimaryServer
        objSCCM("OSDAdapter0EnableWINS") = "true"
        if Not IsNull (objNetAdapter.WINSSecondaryServer) then
         strWins = strWins & "," & objNetAdapter.WINSSecondaryServer
        end if
        WSCript.Echo "WINS Server:      " & strWins
        objSCCM("OSDAdapter0WINSServerList") = strWins
       else
        objSCCM("OSDAdapter0EnableWINS") = "false"
       end if

       objSCCM("OSDAdapterCount") = "1"
          
      end if
     Next
    End If


    Bob
    Thursday, August 25, 2011 2:13 PM
  • Well, there actually is DHCP on the network I am building servers on, but its a Unix DHCP box that has no IP helpers so with the given IP address we can't see the SCCM servers or DPs.  We want DHCP disabled on the NICs.

    Using collection variables previously, one of the variables was OSDAdapter0EnableDHCP = false so you might be right there.  I think if I just change the top of your script near the DHCP part and just disable it right off the bat, we might be in business.


    Thursday, August 25, 2011 2:23 PM
  • Your DHCP address can't see the SCCM servers?  Your networking group needs to go figure out your problem, using static as a fix for a bad DHCP configuration isn't the answer.  I'm not sure why the UNIX guys still control the network these days, with most of my customers they get it wrong a lot more often than they get it right.

    But assuming you can't get the problem fixed, unfortuntely fairly common, modifying the script is probably the best answer.


    Bob
    Thursday, August 25, 2011 2:36 PM
  • Bob,

    I hear what you're screaming.  They have taken over the DHCP and PXE environments with their Opsware deployment tool, and it doesn't play well with others.  Unfortunately that DHCP is a fight we will have to wage later on, but for now we are the red-headed step child.  In my opinion, you either don't have DHCP in your server environment or set it up so it can be used by all people who might need it.  I have modified the script and am running a test.

    And in breaking news, I am still running a test with your original script but tried collection variables (Adapter count=1, enable WINS) and believe it or not it seems to have worked.  IP information survived the reboot, despite not doing anything to actually disable DHCP which is odd.  System came back up from the reboot and resumed the task sequence.  F8 ipconfig confirms all IP info carried over. 

     

    Thursday, August 25, 2011 3:06 PM
  • Yeah, giving the UNIX guys control of the network is the biggest issue I always run into, that's been true for 15 years or so.


    Bob
    Thursday, August 25, 2011 3:40 PM
  • Hi,

     

    I am trying to use this script and having some trouble. Hopefully the OP still gets notified when someone replies. Below is what gets sent back to SCCM when my "Capture Network Settings" TS runs. My command line is as follows cscript scripts\CustomScripts\staticip.vbs. Don't understand why MS just didn't build this functionality in.

    The task sequence execution engine successfully completed the action (Capture Network Settings) in the group (Install Operating System) with exit code 0

    Action output: ng command line: Run command line
    Process completed with exit code 0
    Microsoft (R) Windows Script Host Version 5.8
    Copyright (C) Microsoft Corporation. All rights reserved.

    Number of adapters is 1
    DHCP Disabled
    IP Address:       *.*.*.201
    IP Subnet:        255.255.255.0
    IP Gateway:       *.*.*.1
    DNS Server:       *.*.*.10
    MAC Address:      00:23:AE:62:F8:AA
    ????4???????????4?????????????????????????????????????????????????????????›†††????????????›†††????????????›†††????????????†††????????????›††?????????Command line returned 0
    Entering ReleaseSource() for C:\_SMSTaskSequence\Packages\CR200063
    reference count 1 for the source C:\_SMSTaskSequence\Packages\CR200063 before releasing
    Delete source directory C:\_SMSTaskSequence\Packages\CR200063
    Released the resolved source C:\_SMSTaskSequence\Packages\CR200063
    C:\_SMSTaskSequence\Packages\CR200063\scripts\CustomScripts\staticip.vbs(48, 5) SWbemObjectEx: Invalid index.
    ???????????????????????????????????????????????????????.

     

    EDIT: I believe i figured out the issue. I was not filling in the DNS Suffix. Hell, i wasn't even sure what the DNS suffix was. ::smacks forehead::. Anyway once I placed that info in winpe the script ran perfectly. Thanks for taking the time put this info out. Much appreciated.




    • Edited by PaDocIT Friday, December 23, 2011 4:39 PM
    Friday, December 23, 2011 3:51 PM
  • Glad to see the script is still providing value.  It would be nice if Microsoft would recognize that not everyone is on DHCP, its amazing the number of things that don't work right.

     


    Bob
    Sunday, December 25, 2011 2:47 PM
  • I just used it for SCCM OSD (no MDT) 2012 sp1 and it solved my issues.  Really appreciate it.

    Cyndy

    Monday, March 31, 2014 3:10 PM
  • Does the "Apply Network Settings" step know to automatically use these values?  Do you need to configure this step in any special way?  Thanks!  I'm very pleased to have found this thread!!
    Monday, August 4, 2014 3:19 PM
  • You need to integrate MDT with SCCM. I have my script in my MDT package in a folder called custom scripts.

    Although Cyndy above states she's not using MDT, I wonder how she is retainging the captured info after the "Setup Windows and ConfigMgr" step reboots. Maybe she will chime in. :)

    This is for MDT 2012/SCCM 2012 but the steps are the same no matter the versions  - http://www.windows-noob.com/forums/index.php?/topic/5131-using-sccm-2012-rc-in-a-lab-part-16-integrating-mdt-2012-rc1-with-configuration-manager-2012/

    You will use the Use Toolkit Package step to download your MDT files.

    I then run the script to capture the Network Settings.You then need to add the gather step, this step is what will actually capture your static IP info.

    Apply network settings will just apply things like Domain join, adapter config, etc.




    • Edited by PaDocIT Monday, August 4, 2014 4:02 PM sp
    Monday, August 4, 2014 3:31 PM
  • Thanks!  So then how are folks doing it that are not using MDT (like Cyndy states above)?
    Monday, August 4, 2014 3:36 PM
  • Yeah I edited my post. I'm not sure. For me the gather step was necessary or I would lose my static info after the next reboot.
    Monday, August 4, 2014 3:41 PM
  • I created a package with the script in the source files.  I used a command line to run the script using the package right before the apply network settings.  Works like a charm.

    Cyndy

    Tuesday, August 5, 2014 1:33 AM
  • Thanks Cyndy!  Would you be able to provide screen shots of the task sequence steps (that run the script and the apply network settings)?
    Tuesday, August 5, 2014 2:13 AM
  • It relies on the variables set in Capture Network State, that for some reason SCCM doesn't reapply.  So it will run pretty much as is.

    Bob

    Tuesday, August 5, 2014 3:14 AM
  • You don't need MDT.  The Capture Network Settings grabs what we need, the problem is Apply Network Settings doesn't work quite right with static IP for some reason.  The script takes care of the problem.

    Bob

    Tuesday, August 5, 2014 3:16 AM
  • Variables survive reboot, so it's not an issue :)


    Bob

    Tuesday, August 5, 2014 3:16 AM
  • OK...so I have added the "Capture Network Settings" step to my task sequence, then added a command line step to run the script, and finally the "Apply Network Settings" step.  Do I still need the adapter added to the Apply step, or does the script take care of that?

    

    Tuesday, September 2, 2014 1:22 PM
  • No, I've never set that.  The only time I can see that being needed is in the case where you have multiple NICs, like with a server. They went to the trouble of putting it in, so I'm sure there has to be a reason for it.

    Bob

    Monday, September 8, 2014 12:49 AM
  • Sorry it took a while but I did not have access to the site I had used it.


    Cyndy


    Friday, December 19, 2014 2:23 PM
  • Hi,

    is there a way we can modify the script to capture the Alternate DNS as well ?

    the script works find for me and it captures all the info, but i want to find a way for me to enter the second Alternate DNS value.

    any idea ?

    thanks,

    Tuesday, February 18, 2020 6:13 PM
  • I believe the alternate DNS addresses are in the DNSServerSearchOrder variable.  The variable is an array, so you just add additional values to it.  If you use WBEMTEST to execute the query in the script, you can see the values in the variable.

    Bob

    Tuesday, February 18, 2020 6:53 PM
  • Hi Bob,

    I'm aware that the variable is an array but i can't input 2 DNS IP on the this page. and If i add the OSDAdapter0DNSServerList variable after this window like a pop up to come up like waht i do with OSDComputerName  the task will fail

    Tuesday, February 18, 2020 7:41 PM
  • Ok, I see where you're coming from now. I don't really have a good answer for you unfortunately.  If you use the same DNS servers everywhere, then you could simply hard code it into the script, if it depends on where you're at, that gets a bit trickier. 

    Bob

    Tuesday, February 18, 2020 7:53 PM