I am writing a script to change from dchp to a new static ip address on several servers.
This snippet of code below does work and accomplish the task. However, take note the 2 echos above and below the EnableStatic method. When this runs i never see "done", but the ip changes on the host.
Ok, so I can understand that, ip changes and now connection is lost and wmi freaks out. However, how do I make this exit that line and move on after a couple of seconds. Right now, it changes only the first host in the csv file and hangs.
Im fairly new to this Powershell/WMI but have more experience with batch and bash scripting.
======================================foreach ($f in (import-csv "./parameters.csv")) {$NICs = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $f.Name -filter "IpEnabled = TRUE"Foreach($NIC in $NICs) {echo $f
$DNSServers = $f.DNSWINS1,$f.DNSWINS2
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration(
Change IP script hangs.
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Change IP script hangs.
If you use the WMI command for a single computer, can you get the Done message? I still think you should get a result from the EnableStatic method. Don't use the CSV import and pipeline.
Change IP script hangs.
Even If I set it to one server and hard code all the values it stops. Even if I manually type each line, it will stop. I think its because I am remote and once the ip changes, WMI loses its RCP connection and it doesnt know what to do.
The script changes the server just fine, I think it just wont exit after the ip changes and loses rcp connection. All I think I need to do is come up with a way for this to time out and continue on, or call a separate script and continue without waiting for it to finish.
In a batch world I could use "Call script.bat", but I am not sure how it works in powershell. From what I read, I could use ". ./secondscript.ps1" and the variables will pass, but even this hangs up the whole show.
The script changes the server just fine, I think it just wont exit after the ip changes and loses rcp connection. All I think I need to do is come up with a way for this to time out and continue on, or call a separate script and continue without waiting for it to finish.
In a batch world I could use "Call script.bat", but I am not sure how it works in powershell. From what I read, I could use ". ./secondscript.ps1" and the variables will pass, but even this hangs up the whole show.
Change IP script hangs.
Some ideas:
Set the WMI timeout value.
There are some bugs in PoSH WMI implementation. This may be one of them.
Be sure you have all NET Framework service packs installed in case there is a patch to Management classes.
I would try changing DNS registration first then reconnecting and setting static ip.
Set the WMI timeout value.
There are some bugs in PoSH WMI implementation. This may be one of them.
Be sure you have all NET Framework service packs installed in case there is a patch to Management classes.
I would try changing DNS registration first then reconnecting and setting static ip.
Change IP script hangs.
well it appears from searching the error, that this is RPC not available and there are no more ports. Im rebooting as it comes up all the time now.
UPDATE:
Ya, rebooting made that error go away, im just going to wait it out for now.njcwotx2009-02-20 12:26:31
UPDATE:
Ya, rebooting made that error go away, im just going to wait it out for now.njcwotx2009-02-20 12:26:31
Change IP script hangs.
I have used psexec for mass changes, but in this case, its part of a larger script where we use the powershell extensions for VMware in the vi toolkit. I have it working to create mass amounts of machines all the way execpt this is the last piece!
In the end, I am sure I can change horses a bit and run another type of offshoot process using any of the tools available, Im just trying to stick with the KISS method.
Is there a way I can spawn out a separate process and have the current script continue on, and I also guess I need to figure out a way to pass the values along too.
PS< I did try separating the dynamic registration piece out and it still hangs before 'done'.
njcwotx2009-02-20 12:35:47
In the end, I am sure I can change horses a bit and run another type of offshoot process using any of the tools available, Im just trying to stick with the KISS method.
Is there a way I can spawn out a separate process and have the current script continue on, and I also guess I need to figure out a way to pass the values along too.
PS< I did try separating the dynamic registration piece out and it still hangs before 'done'.
njcwotx2009-02-20 12:35:47
Change IP script hangs.
Here is part of your problem.
YOu have accessed the remote machine with naem "name1" at DNS location nnn.nnn.nnn.nnn. YOu now change tyhe address and have it re-register in DNS.
The local machine session still has the old IP cached so you will nevcer be able to reconnect by name. YOu can, however, reconnect using the new IP or you can quit PowerShell, do a DNS cache refresh (ipconfig /flushdns) and restart PoSH and it will get the new IP from DNS.
Using the Management classes directly, as Jeff suggests, is probably the only reliable way to change the IP state on a remote machine except for using remote scripting. PsExec is very good for this. PoSH v2.0 will also be very good at this.
YOu have accessed the remote machine with naem "name1" at DNS location nnn.nnn.nnn.nnn. YOu now change tyhe address and have it re-register in DNS.
The local machine session still has the old IP cached so you will nevcer be able to reconnect by name. YOu can, however, reconnect using the new IP or you can quit PowerShell, do a DNS cache refresh (ipconfig /flushdns) and restart PoSH and it will get the new IP from DNS.
Using the Management classes directly, as Jeff suggests, is probably the only reliable way to change the IP state on a remote machine except for using remote scripting. PsExec is very good for this. PoSH v2.0 will also be very good at this.
Change IP script hangs.
I agree, the its the changing ip address remotely, it makes complete sense. At this point, I need to find a way to tell my script to 'fire and forget', this way I can launch a batch file and use psexec or something.
I am using PoSH v2 CTP3.
I am using PoSH v2 CTP3.
Change IP script hangs.
Unfortunately I don't believe you will be able to get PoSH to flush the cache as each session keeps it's old lookups once they are don. I would try re-connecting using the IP instead of the name as WMI doesn't really care if you use the IP.
Unfortunately I do not have a place to test this right now. The test system is busy.
Another method that would get around this issue is to use VBScript to reset the IP and run it as an external program. This way each run would be in a new session. Run ipconfig /flushdns a few seconds after changing the IP..
If you have multiple DNS servers this could take up t o30 seconds if you are not connected to teh same primary DNS as the remote system.
The primary (first specified) will be updated and the secondary will have to replicate. If you are using the secondary as your primary then this is an issue.
These are some of the reasons why we have dropped using static IPs. It is easier and more reliable to use permanent DHCP allocations. DHCP can set all of the DNS criteria and it will be certain that all members of teh scope behave the same. Statis setting will float out of sync after a time and will take a large effort to manually troubleshoot and fix each problem.
I have watched domins go completely dead due to bad use of static addressing. COnsider DHCP permanent allocations or DHCP asssigned IPs. These are identical to static and are assigned by MAC address. Once the MAC signs it DHCP gives it the pre-defined IP and set all of the remaining settings.
In AD this also helps AD control DNS and host membership as Site sense can be leveraged around the paired DHCP/DNS.
I never use WINS in AD environments. WINS willcause a whole new set of headches over time and is really only useful in a NetBIOS/NetBEUI setting. AD in NOT NetBIOS.
Unfortunately I do not have a place to test this right now. The test system is busy.
Another method that would get around this issue is to use VBScript to reset the IP and run it as an external program. This way each run would be in a new session. Run ipconfig /flushdns a few seconds after changing the IP..
If you have multiple DNS servers this could take up t o30 seconds if you are not connected to teh same primary DNS as the remote system.
The primary (first specified) will be updated and the secondary will have to replicate. If you are using the secondary as your primary then this is an issue.
These are some of the reasons why we have dropped using static IPs. It is easier and more reliable to use permanent DHCP allocations. DHCP can set all of the DNS criteria and it will be certain that all members of teh scope behave the same. Statis setting will float out of sync after a time and will take a large effort to manually troubleshoot and fix each problem.
I have watched domins go completely dead due to bad use of static addressing. COnsider DHCP permanent allocations or DHCP asssigned IPs. These are identical to static and are assigned by MAC address. Once the MAC signs it DHCP gives it the pre-defined IP and set all of the remaining settings.
In AD this also helps AD control DNS and host membership as Site sense can be leveraged around the paired DHCP/DNS.
I never use WINS in AD environments. WINS willcause a whole new set of headches over time and is really only useful in a NetBIOS/NetBEUI setting. AD in NOT NetBIOS.
Change IP script hangs.
Thanks for all the help. Looks like I will have to reverse course and come up with another way.
I can PSEXEC it or run a script inside the vm host at creation time. While we never had any problems in statically assigning our environment, I could also do the dhcp thing, but there are also things to work out there. I would have to find the mac at creation, then somehow script it to update dhcp. I certainly dont want to have to type all the macs in by hand.
I'm aware AD does not run on WINS, its left in place for some legacy hardware and such. Eventually perhaps it could be phased out, but that is another project.
I can PSEXEC it or run a script inside the vm host at creation time. While we never had any problems in statically assigning our environment, I could also do the dhcp thing, but there are also things to work out there. I would have to find the mac at creation, then somehow script it to update dhcp. I certainly dont want to have to type all the macs in by hand.
I'm aware AD does not run on WINS, its left in place for some legacy hardware and such. Eventually perhaps it could be phased out, but that is another project.