Getting TCP/IP Netbios information

Welcome Forums General PowerShell Q&A Getting TCP/IP Netbios information

This topic contains 10 replies, has 5 voices, and was last updated by

 
Participant
2 years, 7 months ago.

  • Author
    Posts
  • #37725

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 26
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

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

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

  • #37735

    Participant
    Points: 0
    Rank: Member

    Well, that's completely another question 😉

  • #37737

    Participant
    Points: 26
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 26
    Rank: Member

    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

The topic ‘Getting TCP/IP Netbios information’ is closed to new replies.