I'm trying to set a value with the PowerShell cmdled Invoke-CimMethod, but I'm getting an error "Invalid method" and i'm at a bit of a loss at the moment. This is my code
Invoke-CimMethod -Query 'SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=1' -MethodName EnableWINS -Arguments @{WINSEnableLMHostsLookup=[Boolean]$false}
According to the documentation, the argument "WINSEnableLMHostsLookup" should be a bool, but for some reason it just doesn't work this way.
https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/settcpipnetbios-method-in-class-win32-networkadapterconfiguration
Can anyone share some insights?
That is a static method, like in any programming language, not an instance method. You don't need to run some kind of constructor first, or find an existing object. It sets a default. Use -classname with static methods. It's not the most user friendly or well documented.
Invoke-CimMethod -ClassName Win32_NetworkAdapterConfiguration -Arguments @{WINSEnableLMHostsLookup=$false} -MethodName EnableWINS
# or arguments by position
Invoke-CimMethod Win32_NetworkAdapterConfiguration @{WINSEnableLMHostsLookup=$false} EnableWINS
Old way with the wmiclass type accelerator:
$NicClass = [wmiclass]'Win32_NetworkAdapterConfiguration'
$NicClass.EnableWINS($false, $false)
CIM is self-documenting if you really want to dig into it. The qualifiers will say whether a method is static.
get-cimclass Win32_NetworkAdapterConfiguration | % cimclassmethods |
select name,qualifiers
Name Qualifiers
---- ----------
EnableWINS {Implemented, MappingStrings, Static, ValueMap}
Hmm, what is "CQL"?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With