Author Posts

April 14, 2016 at 1:41 am

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.

April 14, 2016 at 1:52 am

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.

April 14, 2016 at 2:20 am

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)"] 
  }
}

April 14, 2016 at 2:46 am

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

April 14, 2016 at 2:54 am

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.

April 14, 2016 at 3:06 am

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

April 14, 2016 at 3:15 am

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

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

April 14, 2016 at 3:17 am

Well, that's completely another question 😉

April 14, 2016 at 3:36 am

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)"]
  }
}

April 14, 2016 at 7:10 am

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 = @{...}

April 14, 2016 at 7:25 am

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