![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Interesting bug (?) using PowerShell, Netsh and Longhorn Came across a fascinating issue today, trying to write some ps1 scripts to set IP addresses within my testing/demo Longhorn VMs. With 2k3/XP I just use netshell scripts. Then I hit a weird issue - some netsh commands do not seem to work from within a powershell script. Let me demonstrate with some snippets: Here is the test-bug.ps1 script: ---- # test-bug.ps1 - test of weird longhorn issue # set dynamic IP to start "Setting dynamic IP - In 10.0.0.0/24 DHCP RANGE" netsh interface ip set address name= "LAN" Source=DHCP netsh interface ip set dns name= "LAN" Source=DHCP ipconfig "now setting static IP" netsh interface ip set address name="LAN" source=static addr=192.168.1.100 mask=255.255.255.0 netsh interface ip set address name="LAN" gateway=192.168.1.254 gwmetric=0 netsh interface ip set dns name="LAN" source=static addr=192.168.1.100 register=Primary ipconfig --- When I run this, from within Powershell, The DHCP bit works, but the static doesn't. Here's the output from my system: ----- PS C:\FOO> .\test-bug.ps1 Setting dynamic IP Windows IP Configuration Ethernet adapter lan: Connection-specific DNS Suffix . : kapoho.net Link-local IPv6 Address . . . . . : fe80::f0bd:6169:2767:a71f%10 IPv4 Address. . . . . . . . . . . : 10.10.1.54 Subnet Mask . . . . . . . . . . . : 255.255.255.0 Default Gateway . . . . . . . . . : 10.10.1.100 now setting static IP Windows IP Configuration Ethernet adapter lan: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::f0bd:6169:2767:a71f%10 Default Gateway . . . . . . . . . : 192.168.1.254 ------ Note that the IP address and gateway are missing. If I wait a few seconds, and re-run the IPConfig here's what I see: Windows IP Configuration Ethernet adapter lan: Connection-specific DNS Suffix . : Link-local IPv6 Address . . . . . : fe80::f0bd:6169:2767:a71f%10 Autoconfiguration IPv4 Address. . : 169.254.167.31 Subnet Mask . . . . . . . . . . . : 255.255.0.0 Default Gateway . . . . . . . . . : 192.168.1.254 --------- WEIRD! But weirder - if I cut/paste the two lines from the batch file into the PowerShell window directly, they work fine. Am I still in a jet-lag triangle?? Finally - who's going to Teched Next week? -- Thomas Lee doctordns@gmail.com MVP - Admin Frameworks and Security |
| | #2 (permalink) |
| Guest | RE: Interesting bug (?) using PowerShell, Netsh and Longhorn Just a thought. Have you tried netsh from a cmd prompt? and what results does it give? -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Thomas Lee" wrote: > > Came across a fascinating issue today, trying to write some ps1 scripts > to set IP addresses within my testing/demo Longhorn VMs. With 2k3/XP I > just use netshell scripts. Then I hit a weird issue - some netsh > commands do not seem to work from within a powershell script. Let me > demonstrate with some snippets: > > Here is the test-bug.ps1 script: > > ---- > # test-bug.ps1 - test of weird longhorn issue > # set dynamic IP to start > "Setting dynamic IP - In 10.0.0.0/24 DHCP RANGE" > > netsh interface ip set address name= "LAN" Source=DHCP > netsh interface ip set dns name= "LAN" Source=DHCP > ipconfig > > "now setting static IP" > netsh interface ip set address name="LAN" source=static > addr=192.168.1.100 mask=255.255.255.0 > netsh interface ip set address name="LAN" gateway=192.168.1.254 > gwmetric=0 > netsh interface ip set dns name="LAN" source=static > addr=192.168.1.100 register=Primary > ipconfig > --- > > When I run this, from within Powershell, The DHCP bit works, but the > static doesn't. Here's the output from my system: > > ----- > PS C:\FOO> .\test-bug.ps1 > Setting dynamic IP > > Windows IP Configuration > Ethernet adapter lan: > Connection-specific DNS Suffix . : kapoho.net > Link-local IPv6 Address . . . . . : fe80::f0bd:6169:2767:a71f%10 > IPv4 Address. . . . . . . . . . . : 10.10.1.54 > Subnet Mask . . . . . . . . . . . : 255.255.255.0 > Default Gateway . . . . . . . . . : 10.10.1.100 > > now setting static IP > > Windows IP Configuration > Ethernet adapter lan: > > Connection-specific DNS Suffix . : > Link-local IPv6 Address . . . . . : fe80::f0bd:6169:2767:a71f%10 > Default Gateway . . . . . . . . . : 192.168.1.254 > ------ > > Note that the IP address and gateway are missing. If I wait a few > seconds, and re-run the IPConfig here's what I see: > > Windows IP Configuration > Ethernet adapter lan: > Connection-specific DNS Suffix . : > Link-local IPv6 Address . . . . . : fe80::f0bd:6169:2767:a71f%10 > Autoconfiguration IPv4 Address. . : 169.254.167.31 > Subnet Mask . . . . . . . . . . . : 255.255.0.0 > Default Gateway . . . . . . . . . : 192.168.1.254 > --------- > > WEIRD! > > But weirder - if I cut/paste the two lines from the batch file into the > PowerShell window directly, they work fine. > > Am I still in a jet-lag triangle?? > > Finally - who's going to Teched Next week? > -- > Thomas Lee > doctordns@gmail.com > MVP - Admin Frameworks and Security > |
| | #3 (permalink) |
| Guest | Re: Interesting bug (?) using PowerShell, Netsh and Longhorn In message <FA956BE4-DEDD-43C1-8237-DAE6018829D8@microsoft.com>, RichS <RichS@discussions.microsoft.com> writes >Just a thought. Have you tried netsh from a cmd prompt? and what >results does it give? Good question. It fails in the same way. :-( -- Thomas Lee doctordns@gmail.com MVP - Admin Frameworks and Security |
| | #4 (permalink) |
| Guest | Re: Interesting bug (?) using PowerShell, Netsh and Longhorn On May 31, 9:14 am, Thomas Lee <t...@psp.co.uk> wrote: > In message <FA956BE4-DEDD-43C1-8237-DAE601882...@microsoft.com>, RichS > <R...@discussions.microsoft.com> writes > > >Just a thought. Have you tried netsh from a cmd prompt? and what > >results does it give? > > Good question. > > It fails in the same way. > > :-( > > -- > Thomas Lee > doctor...@gmail.com > MVP - Admin Frameworks and Security This particular text here: >Note that the IP address and gateway are missing. If I wait a few >seconds, and re-run the IPConfig here's what I see: and this bit here: > Autoconfiguration IPv4 Address. . : 169.254.167.31 Tell me that your attempt to set the source as static is failing. It's still using DHCP to get an address. The "autoconfiguration" text and the non-routable address you've been assigned should alert you to this. I find the best way to get correct NETSH scripts is to use interactive mode (e.g. just run netsh<enter> and use imperative commands to set everything) and then just run "dump <filename>" to get the right script, once you've verified the state of the network. Hope this helps, - Oisin |
| | #5 (permalink) |
| Guest | Re: Interesting bug (?) using PowerShell, Netsh and Longhorn In message <1180620401.518788.312140@p77g2000hsh.googlegroups.com>, Oisin Grehan <oising@gmail.com> writes >On May 31, 9:14 am, Thomas Lee <t...@psp.co.uk> wrote: >> In message <FA956BE4-DEDD-43C1-8237-DAE601882...@microsoft.com>, RichS >> <R...@discussions.microsoft.com> writes >> >> >Just a thought. Have you tried netsh from a cmd prompt? and what >> >results does it give? >> >> Good question. >> >> It fails in the same way. >> >> :-( >> >> -- >> Thomas Lee >> doctor...@gmail.com >> MVP - Admin Frameworks and Security > >This particular text here: > >>Note that the IP address and gateway are missing. If I wait a few >>seconds, and re-run the IPConfig here's what I see: > >and this bit here: > >> Autoconfiguration IPv4 Address. . : 169.254.167.31 Indeed. The two lines in the netsh script fail to 'work' when run from a batch or powershell script, but work interactively. >Tell me that your attempt to set the source as static is failing. Correct. > It's >still using DHCP to get an address. The "autoconfiguration" text and >the non-routable address you've been assigned should alert you to >this. Yes - I know about DHCP. But I don't know why a netsh script to set an address when run form a scrip, yet it runs from the commandline. >I find the best way to get correct NETSH scripts is to use interactive >mode (e.g. just run netsh<enter> and use imperative commands to set >everything) and then just run "dump <filename>" to get the right >script, once you've verified the state of the network. That rather defeats the idea. I have a set of VMs that I generally want to run with static IP addresses to simulate a private network. But from time to time I want to use DHCP so I can access the interent and get stuf (e.g. ms updates) into the VM. The batch script works fine on XP and 2003, but is failing in Longhorn. -- Thomas Lee doctordns@gmail.com MVP - Admin Frameworks and Security |
| | #6 (permalink) |
| Guest | Re: Interesting bug (?) using PowerShell, Netsh and Longhorn On May 31, 11:59 am, Thomas Lee <t...@psp.co.uk> wrote: > In message <1180620401.518788.312...@p77g2000hsh.googlegroups.com>, > Oisin Grehan <ois...@gmail.com> writes > > > > > > >On May 31, 9:14 am, Thomas Lee <t...@psp.co.uk> wrote: > >> In message <FA956BE4-DEDD-43C1-8237-DAE601882...@microsoft.com>, RichS > >> <R...@discussions.microsoft.com> writes > > >> >Just a thought. Have you tried netsh from a cmd prompt? and what > >> >results does it give? > > >> Good question. > > >> It fails in the same way. > > >> :-( > > >> -- > >> Thomas Lee > >> doctor...@gmail.com > >> MVP - Admin Frameworks and Security > > >This particular text here: > > >>Note that the IP address and gateway are missing. If I wait a few > >>seconds, and re-run the IPConfig here's what I see: > > >and this bit here: > > >> Autoconfiguration IPv4 Address. . : 169.254.167.31 > > Indeed. > > The two lines in the netsh script fail to 'work' when run from a batch > or powershell script, but work interactively. > > >Tell me that your attempt to set the source as static is failing. > > Correct. > > > It's > >still using DHCP to get an address. The "autoconfiguration" text and > >the non-routable address you've been assigned should alert you to > >this. > > Yes - I know about DHCP. > > But I don't know why a netsh script to set an address when run form a > scrip, yet it runs from the commandline. > > >I find the best way to get correct NETSH scripts is to use interactive > >mode (e.g. just run netsh<enter> and use imperative commands to set > >everything) and then just run "dump <filename>" to get the right > >script, once you've verified the state of the network. > > That rather defeats the idea. > > I have a set of VMs that I generally want to run with static IP > addresses to simulate a private network. But from time to time I want to > use DHCP so I can access the interent and get stuf (e.g. ms updates) > into the VM. The batch script works fine on XP and 2003, but is failing > in Longhorn. > -- > Thomas Lee > doctor...@gmail.com > MVP - Admin Frameworks and Security- Hide quoted text - > > - Show quoted text - Ok, it wasn't really clear that it "works on XP and 2003, and fails on longhorn" from your initial post. The implication was that a plain netsh script works on xp/2003, but a powershell script doesn't work; the fact it was on longhorn appeared incidental. Anyway, the conclusion (which i'm sure you've come to) is that if both the batch and powershell versions fail only on longhorn, then it's a problem with netsh on longhorn, most likely with how it's interfacing at a system level. Have you tried adding a "sleep 3000" command after the initial attempt to switch your "LAN" i/f into static configuration? Perhaps it's threading/race condition of some sort... also, read back the source property after the wait to verify. This kind of weirdness always descends into voodoo anway, so try wringing the necks of few ceremonial tech-chickens... Yours somewhat redundantly, - Oisin |
| | #7 (permalink) |
| Guest | Re: Interesting bug (?) using PowerShell, Netsh and Longhorn In message <1180641474.509791.219940@g4g2000hsf.googlegroups.com>, Oisin Grehan <oising@gmail.com> writes >Ok, it wasn't really clear that it "works on XP and 2003, and fails on >longhorn" from your initial post. Sorry for the lack of clarity! >The implication was that a plain netsh script works on xp/2003, but a >powershell script doesn't work; the fact it was on longhorn appeared >incidental. Running netsh commands seems to fail when using Longhorn. I first tried it as a powershell script. >Anyway, the conclusion (which i'm sure you've come to) is that if both >the batch and powershell versions fail only on longhorn, then it's a >problem with netsh on longhorn, most likely with how it's interfacing >at a system level. Yes - that seems to be the case. I'll try to file a bug. > Have you tried adding a "sleep 3000" command after the initial attempt >to switch your "LAN" i/f into static configuration? I have not tried this, but it should not be necessary. > Perhaps it's threading/race condition of some sort... also, read back >the source property after the wait to verify. This kind of weirdness >always descends into voodoo anway, so try wringing the necks of few >ceremonial tech-chickens... Good idea - will try later when I get a moment. Thomas -- Thomas Lee doctordns@gmail.com MVP - Admin Frameworks and Security |
| |
| |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Will Longhorn Server be shipped with Powershell 2.0 ? | Yann | PowerShell | 2 | 01-15-2008 08:14 AM |
| interesting code crashes powershell | klumsy@xtra.co.nz | PowerShell | 3 | 04-15-2007 04:32 PM |
| powershell and Longhorn | admin | PowerShell | 1 | 04-03-2007 12:15 PM |
| Powershell on Longhorn Server CTP Feb 2007 | Joop Idema | PowerShell | 1 | 02-22-2007 08:49 AM |
| Powershell for Longhorn IDX Build 6001 | rfalken | PowerShell | 0 | 02-14-2007 03:08 AM |