Is it possible to use get-wmiobject to set network parameters, specifically,
I have two network interfaces with label "outside" and label "inside", I want
to enable "Netbios over TCP/IP and LMHOSTS lookup" for the NIC labeled
"inside".
Thanks in advance,
I had to combine 2 classes to try to make this work on Vista SP1:
$adapter=gwmi -query "select * from win32_networkadapter where
netconnectionid = 'Local Area Connection'"
$config=gwmi -query "select * from win32_networkadapterconfiguration
where index = $($adapter.deviceid)"
$config.WINSEnableLMHostsLookup=$true
# I also tried the above ="True"
$config.put()
I got an error though:
Exception calling "Put" with "0" argument(s): "Provider is not capable
of the attempted operation "
At line:1 char:12
+ $config.put <<<< ()
Perhaps just something with Vista. I'm not able to try another OS at
the moment.
Sounds like in your case, you'd put "inside" where I specified "Local
Area Connection" above.
Marco
--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp
PowerGadgets MVP
http://www.powergadgets.com/mvp
Try this:
## Enable LMHOSTS lookup
([wmiclass]"Win32_NetworkAdapterConfiguration").EnableWINS($null,$true)
## Enable "Netbios over TCP/IP", possible values:
## DEFAULT = 0
## ENABLE = 1
## DISABLE = 2
$adapter=(gwmi -query "select * from win32_networkadapter where netconnectionid
= 'inside'").deviceid
([wmi]"\\.\root\cimv2:Win32_NetworkAdapterConfiguration.Index=$adapter").SetTcpipNetbios(1)
---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Note: When you use the [WMI] type accelerator, you won't be able to
specify alternate credentials, but you may not actually have to
depending on your network setup.
Marco
PS 1> $wmi= [wmiclass]"Win32_NetworkAdapterConfiguration"
PS 2> $wmi.scope.options
Locale :
Username :
Password :
SecurePassword :
Authority :
Impersonation : Impersonate
Authentication : Unchanged
EnablePrivileges : False
Context : {}
Timeout : 10675199.02:48:05.4775807
---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
> Shay Levi wrote:
Thanks. I didn't know that...
Marco
Thanks,
Matt Duguid
$nci = gwmi -q "select * from win32_networkadapter" -computer localhost |
where {$_.NetConnectionID -eq "Local Area Connection 1"}
if($nci){$nci.NetConnectionID="Local Area Connection"; $nci.put()}
---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
MD> Just wondering if anyone has any sample code to set the
MD> NetConnectionID of an adapter. I want to enumerate the adapters on a
MD> server and if they match a condition like "Local Area Connection 1"
MD> want to rename them to something specific.
MD>
MD> Thanks,
MD>
MD> Matt Duguid
MD>
MD> "Marco Shaw [MVP]" wrote:
MD>
Exception calling "Put" with "0" argument(s): "Exception calling "Put" with
"0" argument(s): "Provider is not capable of the attempted operation ""
At C:\temp\nic.ps1:3 char:73
+ if($nci){$nci.NetConnectionID="Local Area Connection New Name";
$nci.put(<<<< )}
Thanks for your time,
--
Matt Duguid
I get the same error on Vista SP1. What OS do you have?
Marco
--
*Microsoft MVP - Windows Server - Admin Frameworks
https://mvp.support.microsoft.com/profile/Marco.Shaw
*PoshComm Co-Community Director - http://www.powershellcommunity.org
*Blog - http://marcoshaw.blogspot.com
--
Matt Duguid
On XP SP2 I get the same error as yours:
Exception calling "Put" with "0" argument(s): "Provider is not capable of
the attempted operation "
It works on Vista SP1:
# get the current netconnectionid
PS > $nci = gwmi -q "select * from win32_networkadapter" -computer localhost
| where {$_.netconnectionid -eq 'Local Area Connection 1'}
PS > $nci.NetConnectionID
Local Area Connection 1
# change it
PS > $nci.NetConnectionID='Local Area Connection'
PS > $nci.put()
Path : \\localhost\root\cimv2:Win32_NetworkAdapter.DeviceID="4"
RelativePath : Win32_NetworkAdapter.DeviceID="4"
Server : localhost
NamespacePath : root\cimv2
ClassName : Win32_NetworkAdapter
IsClass : False
IsInstance : True
IsSingleton : False
# validate the change
PS > gwmi win32_networkadapter -computer localhost -filter "netconnectionid
='Local Area Connection'" | select netconnectionid
netconnectionid
---------------
Local Area Connection
An alrenative would be to change the connection name via netsh.exe, however
the newname option is not valid when administrating a remote machine:
PS > netsh int set int name = "Local Area Connection 1" newname = "New Local
Network Connection Name"
---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
MD> Thanks for the quick response. I tested the code and it finds the
MD> card OK but has an issue when attempting to write back with put().
MD> Does it requires another argument and do I need to use the .set
MD> property anywhere?
MD>
MD> Exception calling "Put" with "0" argument(s): "Exception calling
MD> "Put" with
MD> "0" argument(s): "Provider is not capable of the attempted operation
MD> ""
MD> At C:\temp\nic.ps1:3 char:73
MD> + if($nci){$nci.NetConnectionID="Local Area Connection New Name";
MD> $nci.put(<<<< )}
MD> Thanks for your time,
MD>
MD> "Shay Levi" wrote:
MD>
Yet another valid local method:
$NETWORK_CONNECTIONS = 0x31
$shell = new-object -com shell.application
$netcon = $shell.namespace($NETWORK_CONNECTIONS)
$netcon.items() | where {$_.name -eq 'oldConnectionName'} | foreach {$_.name
= "newConnectionName"}
---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
SL> Hi Matt,
SL>
SL> On XP SP2 I get the same error as yours:
SL>
SL> Exception calling "Put" with "0" argument(s): "Provider is not
SL> capable of the attempted operation "
SL>
SL> It works on Vista SP1:
SL>
SL> # get the current netconnectionid
SL>
PS>> $nci = gwmi -q "select * from win32_networkadapter" -computer
PS>> localhost
PS>>
SL> | where {$_.netconnectionid -eq 'Local Area Connection 1'}
SL>
PS>> $nci.NetConnectionID
PS>>
SL> Local Area Connection 1
SL>
SL> # change it
SL>
PS>> $nci.NetConnectionID='Local Area Connection'
PS>> $nci.put()
SL> Path :
SL> \\localhost\root\cimv2:Win32_NetworkAdapter.DeviceID="4"
SL> RelativePath : Win32_NetworkAdapter.DeviceID="4"
SL> Server : localhost
SL> NamespacePath : root\cimv2
SL> ClassName : Win32_NetworkAdapter
SL> IsClass : False
SL> IsInstance : True
SL> IsSingleton : False
SL> # validate the change
SL>
PS>> gwmi win32_networkadapter -computer localhost -filter
PS>> "netconnectionid
PS>>
SL> ='Local Area Connection'" | select netconnectionid
SL>
SL> netconnectionid
SL> ---------------
SL> Local Area Connection
SL> An alrenative would be to change the connection name via netsh.exe,
SL> however the newname option is not valid when administrating a remote
SL> machine:
SL>
PS>> netsh int set int name = "Local Area Connection 1" newname = "New
PS>> Local
PS>>
SL> Network Connection Name"
SL>
SL> ---
SL> Shay Levi
SL> $cript Fanatic
SL> http://scriptolog.blogspot.com
MD>> Thanks for the quick response. I tested the code and it finds the
MD>> card OK but has an issue when attempting to write back with put().
MD>> Does it requires another argument and do I need to use the .set
MD>> property anywhere?
MD>>
MD>> Exception calling "Put" with "0" argument(s): "Exception calling
MD>> "Put" with
MD>> "0" argument(s): "Provider is not capable of the attempted
MD>> operation
Cheers... ;)
--
Matt Duguid
The NetConnectionID property is read-only on Windows Server 2003 and Windows
XP.
http://msdn.microsoft.com/en-us/library/aa394216(VS.85).aspx
---
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
MD> Thanks for the update. Back at work in a few hours so will try it on
MD> Windows 2008 and will advise outcome. Interested to see the other
MD> method you posted via the shell.application object in powershell as
MD> I have seen a working vbscript example using same object...
MD>
MD> Cheers... ;)
MD>
Powershell...
$NetworkConnectionsMask = 0x31
$Shell = New-Object -com shell.application
$NetworkConnections = $Shell.Namespace($NetworkConnectionsMask)
$NetworkConnections.Items() | where { $_.Name -eq 'Local Area Connection' }
| foreach { $_.Name = "NewName1" }
$NetworkConnections.Items() | where { $_.Name -eq 'Local Area Connection 2'
} | foreach { $_.Name = "NewName2" }
$NetworkConnections.Items() | where { $_.Name -eq 'Local Area Connection 3'
} | foreach { $_.Name = "NewNetworkTeamName" }
VBscript equalivient which we were using on Windows 2003 servers...
Dim objFolder, colItems, objItem
Const NETWORK_CONNECTIONS = &H31&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(NETWORK_CONNECTIONS)
Set colItems = objFolder.Items
For Each objItem in colItems
If objItem.Name = "Local Area Connection" Then
objItem.Name = "NewName1"
End If
If objItem.Name = "Local Area Connection 2" Then
objItem.Name = "NewName2"
End If
If objItem.Name = "Local Area Connection 3" Then
objItem.Name = "NewNetworkTeamName"
End If
Next
Thanks for all your help... ;)
--
Matt Duguid
How can the rename of network connections be done on remote machines using powershell and the com object method but dont have powershell installed locally?
If it can't be done that way then can it be done via gwmi?
Thanks
Zak
> On Wednesday, May 28, 2008 1:27 PM Fran wrote:
> Hi,
>
> Is it possible to use get-wmiobject to set network parameters, specifically,
> I have two network interfaces with label "outside" and label "inside", I want
> to enable "Netbios over TCP/IP and LMHOSTS lookup" for the NIC labeled
> "inside".
>
> Thanks in advance,
>> On Wednesday, May 28, 2008 2:04 PM Marco Shaw [MVP] wrote:
>> Frank wrote:
>>
>> I had to combine 2 classes to try to make this work on Vista SP1:
>>
>> $adapter=gwmi -query "select * from win32_networkadapter where
>> netconnectionid = 'Local Area Connection'"
>> $config=gwmi -query "select * from win32_networkadapterconfiguration
>> where index = $($adapter.deviceid)"
>> $config.WINSEnableLMHostsLookup=$true
>> $config.put()
>>
>> I got an error though:
>> Exception calling "Put" with "0" argument(s): "Provider is not capable
>> of the attempted operation "
>> At line:1 char:12
>> + $config.put <<<< ()
>>
>> Perhaps just something with Vista. I'm not able to try another OS at
>> the moment.
>>
>> Sounds like in your case, you'd put "inside" where I specified "Local
>> Area Connection" above.
>>
>> Marco
>>
>> --
>> Microsoft MVP - Windows PowerShell
>> http://www.microsoft.com/mvp
>>
>> PowerGadgets MVP
>> http://www.powergadgets.com/mvp
>>
>> Blog:
>> http://marcoshaw.blogspot.com
>>> On Thursday, May 29, 2008 4:58 AM Shay Levi wrote:
>>> Hi Frank,
>>>
>>> Try this:
>>>
>>> ([wmiclass]"Win32_NetworkAdapterConfiguration").EnableWINS($null,$true)
>>>
>>>
>>> $adapter=(gwmi -query "select * from win32_networkadapter where netconnectionid
>>> = 'inside'").deviceid
>>> ([wmi]"\\.\root\cimv2:Win32_NetworkAdapterConfiguration.Index=$adapter").SetTcpipNetbios(1)
>>>
>>>
>>> ---
>>> Shay Levi
>>> $cript Fanatic
>>> http://scriptolog.blogspot.com
>>>> On Thursday, May 29, 2008 7:41 AM Marco Shaw [MVP] wrote:
>>>> Shay Levi wrote:
>>>>
>>>> Note: When you use the [WMI] type accelerator, you will not be able to
>>>> specify alternate credentials, but you may not actually have to
>>>> depending on your network setup.
>>>>
>>>> Marco
>>>>> On Friday, June 27, 2008 1:32 AM MattDugui wrote:
>>>>> Just wondering if anyone has any sample code to set the NetConnectionID of an
>>>>> adapter. I want to enumerate the adapters on a server and if they match a
>>>>> condition like "Local Area Connection 1" want to rename them to something
>>>>> specific.
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Matt Duguid
>>>>>
>>>>>
>>>>> "Marco Shaw [MVP]" wrote:
>>>>>> On Saturday, June 28, 2008 9:35 PM MattDugui wrote:
>>>>>> Thanks for the quick response. I tested the code and it finds the card OK but
>>>>>> has an issue when attempting to write back with put(). Does it requires
>>>>>> another argument and do I need to use the .set property anywhere?
>>>>>>
>>>>>> Exception calling "Put" with "0" argument(s): "Exception calling "Put" with
>>>>>> "0" argument(s): "Provider is not capable of the attempted operation ""
>>>>>> At C:\temp\nic.ps1:3 char:73
>>>>>> + if($nci){$nci.NetConnectionID="Local Area Connection New Name";
>>>>>> $nci.put(<<<< )}
>>>>>>
>>>>>> Thanks for your time,
>>>>>> --
>>>>>> Matt Duguid
>>>>>>
>>>>>>
>>>>>> "Shay Levi" wrote:
>>>>>>> On Saturday, June 28, 2008 9:44 PM Marco Shaw [MVP] wrote:
>>>>>>> Matt Duguid wrote:
>>>>>>>
>>>>>>> I get the same error on Vista SP1. What OS do you have?
>>>>>>>
>>>>>>> Marco
>>>>>>>
>>>>>>> --
>>>>>>> *Microsoft MVP - Windows Server - Admin Frameworks
>>>>>>> https://mvp.support.microsoft.com/profile/Marco.Shaw
>>>>>>> *PoshComm Co-Community Director - http://www.powershellcommunity.org
>>>>>>> *Blog - http://marcoshaw.blogspot.com
>>>>>>>> On Saturday, June 28, 2008 10:19 PM MattDugui wrote:
>>>>>>>> Am testing on XP SP3 but aiming to use this on Windows 2008 Server. I have
>>>>>>>> managed to set the IP/SN/GW/DNS/NbtOverTCP/etc with no problem just the
>>>>>>>> NetConnectionID seems to be a little trickier. There are plenty of vbscript
>>>>>>>> examples but a lack of powershell ones... ;)
>>>>>>>>
>>>>>>>> --
>>>>>>>> Matt Duguid
>>>>>>>>
>>>>>>>>
>>>>>>>> "Marco Shaw [MVP]" wrote:
>>>>>>>>> On Sunday, June 29, 2008 5:42 AM MattDugui wrote:
>>>>>>>>> Thanks for the update. Back at work in a few hours so will try it on Windows
>>>>>>>>> 2008 and will advise outcome. Interested to see the other method you posted
>>>>>>>>> via the shell.application object in powershell as I have seen a working
>>>>>>>>> vbscript example using same object...
>>>>>>>>>
>>>>>>>>> Cheers... ;)
>>>>>>>>> --
>>>>>>>>> Matt Duguid
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> "Shay Levi" wrote:
>>>>>>>>>> On Sunday, June 29, 2008 7:08 PM MattDugui wrote:
>>>>>>>>>> Tested the powershell example you provided below on Windows 2008 Web Edition
>>>>>>>>>> and all good! We are configuring the NIC's to be teamed via HP command line
>>>>>>>>>> tool (cqniccmd.exe) then use the powershell script to configure the names/ip
>>>>>>>>>> stack as part of our scripted server builds...
>>>>>>>>>>
>>>>>>>>>> Powershell...
>>>>>>>>>>
>>>>>>>>>> $NetworkConnectionsMask = 0x31
>>>>>>>>>> $Shell = New-Object -com shell.application
>>>>>>>>>> $NetworkConnections = $Shell.Namespace($NetworkConnectionsMask)
>>>>>>>>>>
>>>>>>>>>> $NetworkConnections.Items() | where { $_.Name -eq 'Local Area Connection' }
>>>>>>>>>>
>>>>>>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>>>>>>> ComponentOne Studio for ASP.NET AJAX - Free License Giveaway
>>>>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/ce98ce1f-2b5d-4ec8-b6d5-a1049651514e/componentone-studio-for-aspnet-ajax--free-license-giveaway.aspx