Windows Vista Forums

Problem using EnableStatic to remotely set IP address

  1. #1



    Newbie
    Join Date : Jun 2009
    Posts : 4
    Vista Enterprise 32-bit
    Local Time: 02:43 PM

    Problem using EnableStatic to remotely set IP address

    Hi all,
    I'm attempting to update the network adapter config remotely for hundreds of machines from using DHCP to using new and statically assigned IP's. I've come up with the following script from reading others' posts, using Get-Member, and a little blind luck...

    It works fine up until the point it sends the EnableStatic command, causing my script to hang. In fact, this line does its work ok on the remote machine. It successfully sets the IP and Subnet settings, and the remote machine works just fine after that. But *I think* in doing so, the network connection gets reset after the new settings are applied, causing my connection to the machine to be broken, and causing my script to just hang waiting for the result/response to come back and not move on to process the next host.

    Is there a way to tell my script NOT to wait for the response and just proceed with the remainder of the script? Or is there another way I should be attempting to do this operation?


    Thanks in advance.
    -wwar1ace

    ===SCRIPT===
    ## Testing with a group of 10 machines:
    ## "host_info.csv" contains records with hostname, MAC, and myIP.
    ## All other values (cred, myGW, myDNS, mySUBNET) are set by an init script.

    $hosts=Import-Csv "host_info.csv"

    Foreach($machine in $hosts){
    $LANs=(gwmi -Class Win32_NetworkAdapterConfiguration -Comp $machine.hostname -cred $cred)|where{$_.MACAddress -eq $machine.MAC}

    Foreach($NIC in $LANs) {
    "Set Gateways:"
    $NIC.SetGateways($myGW)
    "Turn OFF DNS Reg"
    $NIC.SetDynamicDNSRegistration($false)
    "Set DNS Server Order"
    $NIC.SetDNSServerSearchOrder($myDNS)
    "Enable Static IP:"
    $NIC.EnableStatic($machine.myIP,$mySUBNET)
    "Static Enabled"
    }
    }
    ===END SCRIPT===

      My System SpecsSystem Spec

  2.   


  3. #2


    Al Dunbar Guest

    Re: Problem using EnableStatic to remotely set IP address


    "wwar1ace" <guest@xxxxxx-email.com> wrote in message
    news:c0309762cb342f2d38f16fcf89be3c63@xxxxxx-gateway.com...

    >
    > Hi all,
    > I'm attempting to update the network adapter config remotely for
    > hundreds of machines from using DHCP to using new and statically
    > assigned IP's.
    Some would call that a step backwards. How are you planning on managing the
    fixed IP's as machines are added and retired?

    > I've come up with the following script from reading
    > others' posts, using Get-Member, and a little blind luck...
    >
    > It works fine up until the point it sends the EnableStatic command,
    > causing my script to hang. In fact, this line does its work ok on the
    > remote machine. It successfully sets the IP and Subnet settings, and the
    > remote machine works just fine after that. But *I think* in doing so,
    > the network connection gets reset after the new settings are applied,
    > causing my connection to the machine to be broken, and causing my script
    > to just hang waiting for the result/response to come back and not move
    > on to process the next host.
    Seems the most likely cause of your script's problem...

    > Is there a way to tell my script NOT to wait for the response and just
    > proceed with the remainder of the script? Or is there another way I
    > should be attempting to do this operation?


    >
    > Thanks in advance.
    > -wwar1ace
    >
    > ===SCRIPT===
    > ## Testing with a group of 10 machines:
    > ## "host_info.csv" contains records with hostname, MAC, and myIP.
    > ## All other values (cred, myGW, myDNS, mySUBNET) are set by an init
    > script.
    >
    > $hosts=Import-Csv "host_info.csv"
    >
    > Foreach($machine in $hosts){
    > $LANs=(gwmi -Class Win32_NetworkAdapterConfiguration -Comp
    > $machine.hostname -cred $cred)|where{$_.MACAddress -eq $machine.MAC}
    >
    > Foreach($NIC in $LANs) {
    > "Set Gateways:"
    > $NIC.SetGateways($myGW)
    > "Turn OFF DNS Reg"
    > $NIC.SetDynamicDNSRegistration($false)
    > "Set DNS Server Order"
    > $NIC.SetDNSServerSearchOrder($myDNS)
    > "Enable Static IP:"
    > $NIC.EnableStatic($machine.myIP,$mySUBNET)
    > "Static Enabled"
    > }
    >
    > }
    > ===END SCRIPT===
    >
    >
    > --
    > wwar1ace



      My System SpecsSystem Spec

  4. #3



    Newbie
    Join Date : Jun 2009
    Posts : 4
    Vista Enterprise 32-bit
    Local Time: 02:43 PM


      Thread Starter

    Re: Problem using EnableStatic to remotely set IP address

    Quite true, in general... But there are reasons for it here. We run in a pretty complex environment (with a DHCP server AND registered IP's) that does not belong to us, meaning that the network infrastructure is not ours and we cannot manage it if something goes wrong with a server or other piece of network hardware. We've found it beneficial to have the IP info hardcoded on the machine for just these times.

    Management during turnover is not an issue, as the machines have to be setup anyhow. But right now we're going through a change of subnets for entire buildings that are related to a major network upgrade there.

    -wwar1ace

    Quote Originally Posted by Al Dunbar View Post
    "wwar1ace" <guest@xxxxxx-email.com> wrote in message
    news:c0309762cb342f2d38f16fcf89be3c63@xxxxxx-gateway.com...
    >
    > Hi all,
    > I'm attempting to update the network adapter config remotely for
    > hundreds of machines from using DHCP to using new and statically
    > assigned IP's.
    Some would call that a step backwards. How are you planning on managing the
    fixed IP's as machines are added and retired?

      My System SpecsSystem Spec

  5. #4



    Newbie
    Join Date : Jun 2009
    Posts : 4
    Vista Enterprise 32-bit
    Local Time: 02:43 PM


      Thread Starter

    Re: Problem using EnableStatic to remotely set IP address

    Yeah, I agree... but I would like to find out whether 1) I'm not doing something as I should be doing it, like some other option or switch I should be using or 2) the EnableStatic functionality is not fully developed in v1.0 and trying to use it on a remote machine causes my PS script to *break*.




    Quote Originally Posted by Al Dunbar View Post
    "wwar1ace" <guest@xxxxxx-email.com> wrote in message
    news:c0309762cb342f2d38f16fcf89be3c6...gateway.com...


    > ...But *I think* in doing so,
    > the network connection gets reset after the new settings are applied,
    > causing my connection to the machine to be broken, and causing my script
    > to just hang waiting for the result/response to come back and not move
    > on to process the next host.
    Seems the most likely cause of your script's problem...



      My System SpecsSystem Spec


Problem using EnableStatic to remotely set IP address
Similar Threads
Thread Forum
execution policy problem executing remotely with hpc job scheduler PowerShell
Problem reading registry remotely PowerShell
PS WMI problem remotely PowerShell
WMI EnableStatic not work in Vista Vista networking & sharing
WMI EnableStatic not work in Vista Vista networking & sharing