Answered by:
How to disable LMHOSTS lookup in Powershell 5

Question
-
As I understand, previously it could be made with
$nic = Get-WmiObjectWin32_NetworkAdapterConfiguration-filter"ipenabled = 'true'"
$nic.enablewins($false,$false)
but now
this class doesn't have such method (.Enablewins)
Is it possible to disable LMHOSTS lookup with powershell 5?
Friday, April 6, 2018 11:11 AM
Answers
-
We can also do this:
$nicClass = Get-WmiObject -list Win32_NetworkAdapterConfiguration $nicClass.enablewins($false,$false)
\_(ツ)_/
- Marked as answer by Kupriyanov Friday, April 6, 2018 1:55 PM
Friday, April 6, 2018 1:38 PM
All replies
-
(Get-CimInstanceWin32_NetworkAdapterConfiguration-filter"ipenabled = 'true'") |gm
shows that the WINSEnableLMHostsLookup property is read-only, so set-ciminstance doesn't work either.
Friday, April 6, 2018 11:15 AM -
By default there is no LMHOSTS file. If a file exists it will be listed. The checkbox is meaningless if no file is listed.
To get more information on this post in the Windows Networking Forum.
The value is maintained globally in the registry here:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\EnableLMHosts
\_(ツ)_/
Friday, April 6, 2018 11:59 AM -
So the only way to disable it is to modify registry? No PowerShell way?Friday, April 6, 2018 12:08 PM
-
You can use powershell to modify registry.. so it is powershell´ish way imo .. :)
Not every tweak has its own cmdlet.
Friday, April 6, 2018 12:32 PM -
Who says there are no CmdLets. Poppycock.
function Get-LMHosts{ (Get-ItemProperty hklm:\SYSTEM\CurrentControlSet\Services\NetBT\Parameters -name EnableLMHOSTS).EnableLMHOSTS } function Enable-LMHosts{ Write-Warning 'This command must run elevated' -Verbose Set-ItemProperty hklm:\SYSTEM\CurrentControlSet\Services\NetBT\Parameters -name EnableLMHOSTS -Value 1 }
\_(ツ)_/
Friday, April 6, 2018 12:44 PM -
I forgot about Static Classes (square brackets). So you can make it PoSH way
$Arguments = @{ DNSEnabledForWINSResolution = $false WINSEnableLMHostsLookup = $false } Invoke-CimMethod -ClassName Win32_NetworkAdapterConfiguration -MethodName EnableWINS -Arguments $Arguments
or
$nicall = [wmiclass]'Win32_NetworkAdapterConfiguration' $nicall.enablewins($false,$false)
In Russian you can read it here
- Proposed as answer by jrv Friday, April 6, 2018 1:36 PM
Friday, April 6, 2018 1:33 PM -
Yes. I forgot to check the class and only looked at the instances. Good call.
\_(ツ)_/
Friday, April 6, 2018 1:36 PM -
We can also do this:
$nicClass = Get-WmiObject -list Win32_NetworkAdapterConfiguration $nicClass.enablewins($false,$false)
\_(ツ)_/
- Marked as answer by Kupriyanov Friday, April 6, 2018 1:55 PM
Friday, April 6, 2018 1:38 PM -
Yep, you're right :)
So I could just put '-list' in my command.
Friday, April 6, 2018 1:55 PM -
The mistake is that many sites document the WINS methods as part of the instance. They are global so they are only defined on the class. They are like "static" methods on a Net class. If we read the documentation carefully this is clearly stated.
EnableWINS method of the Win32_NetworkAdapterConfiguration class
The EnableWINS WMI class static method enables Windows Internet Naming Service (WINS) settings specific to TCP/IP, but independent of the network adapter.https://msdn.microsoft.com/en-us/library/aa390384(v=vs.85).aspx
\_(ツ)_/
- Edited by jrv Friday, April 6, 2018 2:13 PM
Friday, April 6, 2018 2:13 PM