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.
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 ![:wink: :wink:](https://emoji.discourse-cdn.com/twitter/wink.png?v=12)
The properties appear to be there, but they are empty.
Oh wait, nevermind. they are not, was querying wrong adapter.
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)"]
}
}
Can’t argue with the last post ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=12)
Important thing to remember regarding WMI is to filter in Get-WmiObject (or Get-CimInstance) using the -Filter parameter rather than using where-object
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.
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
That gives 0 , but there is no indication what that means.
The output suggested by Richard was what I wanted. Thanks fore replying
Well, that’s completely another question ![:wink: :wink:](https://emoji.discourse-cdn.com/twitter/wink.png?v=12)
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)"]
}
}
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 = @{...}
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