Windows Vista Forums

Get-WMIObject Win32_NetworkAdapterConfiguration

  1. #1



    Newbie
    Join Date : Feb 2010
    Posts : 2
    Windows 7
    Local Time: 11:27 PM

    Get-WMIObject Win32_NetworkAdapterConfiguration

    I have the following code I use to try to change the settings on our servers from dhcp to static. It gets "hung" up on the enablestatic() peice, I know its because after it changes the ip it looses the connection but how do I get Powershell to either fork off this command or time out earler. BTW it makes the changes it just stays hung for a long time before moving onto other machines. Any help appreciated (there are a few extral lines in there that I was playing around with to see if I could get it to work)

    # Connect-VIServer server
    function set-ip {
    # param (
    # [Parameter(Mandatory=$True, HelpMessage="Enter an CSV filename, eg. servers.xml", ParameterSetName = "One")]`
    # [string]$File )
    $Global:newcsv = Import-CSV iptest1.csv
    $NewCsv |ForEach-Object {
    $Global:NAME = $_.NAME
    [string]$Global:ipaddr = $_.ipaddr
    [string]$Global:subnet = $_.subnet
    $Global:NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -ComputerName $NAME | where{$_.IPEnabled -eq “TRUE”}
    #Get-WmiObject -list win32_networkadapterconfiguration -ComputerName $NAME
    foreach($Global:NIC in $NICs) {
    $gway = $_.gway
    $DNSServers = $_.DNS1,$_.DNS2
    $NIC.SetWINSServer($_.Wins1,$_.Wins2)
    Write-Host "WINS Set"
    $_.Wins1,$_.Wins2
    $NIC.SetGateways($gway)
    Write-Host "GateWay Set"
    $_.gway
    $NIC.SetDNSServerSearchOrder($DNSServers)
    Write-Host "DNS Set"
    $DNSServers
    $NIC.SetDynamicDNSRegistration($TRUE,$TRUE)
    Write-Host "DNS Registration Set"
    $NIC.SetTcpipNetbios($TRUE)
    Write-Host "Netbios Over TCPIP"
    $DNSSuffix = @("lion.com"),@("cat.com"),@("rat.loc"),@("bat.com")
    #$nic1 = [wmiclass] "win32_networkadapterconfiguration"
    $Global:NIC1 = Get-WmiObject -list win32_networkadapterconfiguration -ComputerName $_.Name
    $nic1.SetDNSSuffixSearchOrder($DNSSuffix)
    #Invoke-WmiMethod -path Win32_NetworkAdapterConfiguration -Name SetDNSSuffixSearchOrder -ArgumentList $DNSSuffix

    #$global:nicST = Gwmi win32_NetworkAdapterConfiguration
    # Start-Job -ScriptBlock {
    #$NIC = Get-WMIObject Win32_NetworkAdapterConfiguration -ComputerName $NAME
    # $Global:NICw = Get-WMIObject Win32_NetworkAdapterConfiguration -ComputerName $NAME
    # $NICs.psbase.scope.options.timeout = 5 * 10000000
    # $NICw.EnableStatic("10.4.39.37","255.255.255.0")
    $NIC.EnableStatic($ipaddr,$subnet)
    Write-Host "IP and SubNet Set"
    $_.IPaddr
    $_.Subnet
    #}

    # $NIC.SetDNSDomain($_.DNSDom)
    # $_.DNSDom
    #$NIC.SetDynamicDNSRegistration($TRUE,$TRUE)
    # $VLAN = $_.VLAN
    # Get-VM $_.Name | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $VLAN
    # $_.VLAN
    }
    }
    }
    set-ip


      My System SpecsSystem Spec

  2. #2


    Marco Shaw [MVP] Guest

    Re: Get-WMIObject Win32_NetworkAdapterConfiguration

    Well, you could set these as background jobs? Are you using PowerShell v2?

    There's something else I might try out in the next few days where you might
    be able to time out WMI calls, but you'd have to use .NET classes...

    Marco

    "adrianallan" <guest@newsgroup-email.com> wrote in message
    news:8fccd7071f071014f6bc7de51f737413@newsgroup-gateway.com...

    >
    > I have the following code I use to try to change the settings on our
    > servers from dhcp to static. It gets "hung" up on the enablestatic()
    > peice, I know its because after it changes the ip it looses the
    > connection but how do I get Powershell to either fork off this command
    > or time out earler. BTW it makes the changes it just stays hung for a
    > long time before moving onto other machines. Any help appreciated (there
    > are a few extral lines in there that I was playing around with to see if
    > I could get it to work)


      My System SpecsSystem Spec

  3. #3



    Newbie
    Join Date : Feb 2010
    Posts : 2
    Windows 7
    Local Time: 11:27 PM


      Thread Starter

    Re: Get-WMIObject Win32_NetworkAdapterConfiguration

    That would be great if a .Net procedure would work, I am willing to try out anything

      My System SpecsSystem Spec

Get-WMIObject Win32_NetworkAdapterConfiguration

Similar Threads
Thread Thread Starter Forum Replies Last Post
using get-wmiobject Win32_logicaldisk jgiddyup PowerShell 6 24 Dec 2008
Win32_NetworkAdapterConfiguration WMI-ness... lhoff2005 PowerShell 2 01 Aug 2008
Win32_NetworkAdapterConfiguration methods and properties Nikhil R. Bhandari PowerShell 0 16 Mar 2007
Get-WmiObject Win32_Product Keith Hill PowerShell 6 26 Feb 2007
get-wmiobject IT Staff PowerShell 6 19 Oct 2006