Getting TCP/IP Netbios information

This topic contains 10 replies, has 5 voices, and was last updated by Profile photo of Richard Diphoorn Richard Diphoorn 7 months, 3 weeks ago.

  • Author
    Posts
  • #37725
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    I would like to get information from WMI in regards to whether NetBios is enabled over TCP/IP.

    I have used the below syntax:

    Get-wmiobject -ClassName Win32_NetworkAdapterConfiguration | where {$_.servicename -eq  "vmxnet3ndis6" -and $_.Index -eq "9"} | select -ExpandProperty tcpipnetbiosoptions
    
    

    But I am getting no response.

    Any help most appreciated.

  • #37726

    Why would you do that:

    where {$_.servicename -eq  "vmxnet3ndis6" -and $_.Index -eq "9"}

    If you know the index just go for index.

    On the actual matter I have the same behavior 😉
    The properties appear to be there, but they are empty.
    Oh wait, nevermind. they are not, was querying wrong adapter.

  • #37728
    Profile photo of Richard Diphoorn
    Richard Diphoorn
    Participant

    You don't need to expand the property. Try this:

    Get-WmiObject -Class Win32_NetWorkAdapterConfiguration | where { $_.IPEnabled -eq $true } | Select-Object -Property Index,TcpipNetbiosOptions
    

    In Richard Siddaway's book about PowerShell and WMI, he has a cool solution to provide better output. I slightly modified his code.

    #requires -Version 2
    $nbstatus = DATA 
    {
      ConvertFrom-StringData -StringData @'
    0 = EnableNetbiosViaDhcp
    1 = EnableNetbios
    2 = DisableNetbios
    '@
    }
    
    Get-WmiObject -Class Win32_NetWorkAdapterConfiguration |
    Where-Object -FilterScript {
      $_.IPEnabled -eq $true 
    } |
    Select-Object -Property Index, @{
      N = 'NetBIOSOption'
      E = {
        $nbstatus["$($_.TcpipNetbiosOptions)"] 
      }
    }
    
  • #37729
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    Can't argue with the last post 🙂

    Important thing to remember regarding WMI is to filter in Get-WmiObject (or Get-CimInstance) using the -Filter parameter rather than using where-object

  • #37731
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    Thanks to the two Richards, that worked like a charm.

    @RichardSidddaway, I'll change the setting so that all my where-objects are in filterscripts.
    Thanks.

  • #37732

    Actually I have no idea why the code above wasn't working for you, its working for me without any issues:

    C:\WINDOWS\system32> Get-wmiobject -ClassName Win32_NetworkAdapterConfiguration | where {$_.index -eq 1} | select -ExpandProperty tcpipnetbiosoptions
    0
  • #37734
    Profile photo of Wei-Yen Tan
    Wei-Yen Tan
    Participant

    That gives 0 , but there is no indication what that means.

    The output suggested by Richard was what I wanted. Thanks fore replying

  • #37735

    Well, that's completely another question 😉

  • #37737
    Profile photo of Richard Diphoorn
    Richard Diphoorn
    Participant

    Modified the code a bit with the suggestion of Richard Siddaway, to use the Filter parameter.

    #requires -Version 2
    $nbstatus = DATA 
    {
      ConvertFrom-StringData -StringData @'
    0 = EnableNetbiosViaDhcp
    1 = EnableNetbios
    2 = DisableNetbios
    '@
    }
    
    Get-WmiObject -Class Win32_NetWorkAdapterConfiguration -Filter "IPEnabled=$true" | Select-Object -Property Index, @{
      N = 'NetBIOSOption'
      E = {
        $nbstatus["$($_.TcpipNetbiosOptions)"]
      }
    }
    
  • #37768
    Profile photo of Anthony Stringer
    Anthony Stringer
    Participant

    sorry to hijack, but where can i find out more about what this part means?

    $nbstatus = DATA {...}
    

    also, why do that rather than this?

    $nbstatus = @{...}
    
  • #37770
    Profile photo of Richard Diphoorn
    Richard Diphoorn
    Participant

    The main reason for the DATA section is to separate the code from data. And this separation you normally want to do if you are going to produce re-usable tools, like Functions or Modules. This functionality was introduced in PowerShell v2.

    You can find more information in the help topic about Data Sections:

    Get-Help about_Data_Sections
    

    Or online: https://technet.microsoft.com/en-us/library/hh848302(v=wps.620).aspx

You must be logged in to reply to this topic.