How to find the wifi adapter for different languages with PowerShell - windows

A powershell script should enable/disable the wireless network adapter.
So i make use of the NetAdaper cmdlet.
Get-NetAdapter
Enable-NetAdapter -Name 'Wi-Fi'-Confirm:$false
Disable-NetAdapter -Name 'Wi-Fi'-Confirm:$false
Its works fine on english language systems.
On system with other languages configured it fails due to the wireless adapter does not have "Wi-Fi" as name.
Example would be german.
Enable-NetAdapter -Name 'WLAN'-Confirm:$false
Disable-NetAdapter -Name 'WLAN'-Confirm:$false
How to archive this script running on all languages?

Get-NetAdapter has a field named InterfaceType which contains a value based on this enum:
https://learn.microsoft.com/en-us/dotnet/api/system.net.networkinformation.networkinterfacetype?view=net-5.0
According to that documentation, type 71 is a Wireless80211 device.
Just to show it's there:
[int][System.Net.NetworkInformation.NetworkInterfaceType]::Wireless80211
So you could do something like this:
Get-NetAdapter | Where-Object InterfaceType -eq 71
Which will return a list of all wireless adapters.

Related

How to get Bluetooth device battery percentage using PowerShell on windows?

I am trying to plot a graph for Bluetooth headphone battery discharge. For that I need to read battery percentage of the connected device. I can see power information is available on GUI for the device. Is there any way to get the battery percentage info for connected Bluetooth device using PowerShell? (like using wmi or anything else)
In my findings, you can get information on Bluetooth devices using the Get-PnpDevice cmdlet. This should return a list of PnP Devices, their Status, Class, FriendlyName and InstanceID.
Get-PnpDevice
You can filter the results with -Class parameter. To specify Bluetooth PnP devices, you can enter "Bluetooth" as a string value for the -Class parameter.
Get-PnpDevice -Class 'Bluetooth'
You can then specify the device you have in mind from this list by their FriendlyName using the -FriendlyName parameter and enter the desired device's FriendlyName as a string value for the parameter.
Get-PnpDevice -Class 'Bluetooth' -FriendlyName 'Device FriendlyName'
Note: You can also specify the device using the -InstanceId parameter and providing the device's InstanceId as a string value for the parameter.
If you then pipe the previous command to the Get-PnpDeviceProperty cmdlet, it will return a list of the device's properties, including its InstanceId, KeyName, Type and Data.
Get-PnpDevice -Class 'Bluetooth' -FriendlyName 'Device FriendlyName' |
Get-PnpDeviceProperty
Beyond this point, I was able to further filter the results of the command by using the -KeyName parameter and entering the KeyName of the property that (I assume) contains Device Power Data as a string value for the parameter.
Get-PnpDevice -Class 'Bluetooth' -FriendlyName 'Device FriendlyName' |
Get-PnpDeviceProperty -KeyName 'PropertyKeyName'
Unfortunately this is as far as I've gotten to solving the problem. Hopefully my contribution helps.
As far as I am aware, there is no way to poll bluetooth device data beyond what you would get with Get-WmiObject, since the battery status seen in Windows Settings -> Bluetooth Devices is something coming from the vendors/devices driver and seems to, as of now, be inaccessible by PowerShell, unless there is some exotic snapin I am not aware of.
You can get all possible device information via this command:
Get-WmiObject -Query "select * from win32_PnPEntity" | Where Name -like "MyDeviceName"
Or if you are unsure how the device is named as of now, this would return a complete list of "devices":
Get-WmiObject -Query "select * from win32_PnPEntity" | Select Name
Additionally, I couldn't find battery information in the registry - maybe someone more knowledge can expand on that because the registry probably contains the necessary information as it must be stored somewhere on the device.
Paulo Amaral's comment above is indeed the answer.
The code below will provide you with a command you can reuse to query the battery state of your device:
Get-PnpDevice -FriendlyName "*<Device Name>*" | ForEach-Object {
$local:test = $_ |
Get-PnpDeviceProperty -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2' |
Where Type -ne Empty;
if ($test) {
"To query battery for $($_.FriendlyName), run the following:"
" Get-PnpDeviceProperty -InstanceId $($test.InstanceId) -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2' | % Data"
""
"The result will look like this:";
Get-PnpDeviceProperty -InstanceId $($test.InstanceId) -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2' | % Data
}
}
For my <Headset> device, the output looked similar to:
To query battery for <Headset>, run the following:
Get-PnpDeviceProperty -InstanceId BTHENUM\{0000####-0000-####-####-############}_VID&########_PID&####\#&########&#&############_######### -KeyName '{104EA319-6EE2-4701-BD47-8DDBF425BBE5} 2'
The result will look like this:
90

How to list bluetooth devices near me using PowerShell

How to list all Bluetooth devices paired or currently near me and particullary MAC adress ? I want the equivalent of the command :
netsh wlan show network mode=bssid
I am able to list all Bluetooth devices and characteristics but not MAC adress with the command :
Get-PnpDevice | Where-Object {$_.Class -eq "Bluetooth"}
foreach ($device in $devices) { echo $device.InstanceId }
Note it is not a problem if I need to manually shrink results and if the list is not in a perfect layout.
The PowerShell command :
Get-ChildItem -Path HKLM:\SYSTEM\ControlSet001\Services\DeviceAssociationService\State\Store\ | Select-String -Pattern Bluetooth
will print devices already paired :
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\DeviceAssociationService\State\Store\Bluetooth#BluetoothXX:XX:XX:XX:XX:b2-YY:YY:YY:YY:YY:YY
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\DeviceAssociationService\State\Store\Bluetooth#BluetoothXX:XX:XX:XX:XX:b2-ZZ:ZZ:ZZ:ZZ:ZZ:ZZ
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\DeviceAssociationService\State\Store\BluetoothLE#BluetoothLEXX:XX:XX:XX:XX:b2-WW:WW:WW:WW:WW:WW
The XX:XX:XX:XX:XX values is your Bluetooth MAC adress.

how to get unidentified network adaptor name with batch

I already knew how to get all network adaptors names, but I can't tell the difference between normally using and not identified
By using
netsh interface ip show interfaces
or other commands ,you may get all adaptors names.
The necessary information can be obtained using the Win32_NetworkAdapter class.For example:
Get-CimInstance -ClassName Win32_NetworkAdapter -Filter #'
NetConnectionID = "Local Area Connection" AND
NetConnectionStatus=2 AND NetEnabled = True AND PhysicalAdapter = True
'# | Format-List *
The Get-WmiObject cmdlet can also be used, but starting in PowerShell 3.0, it has been superseded by Get-CimInstance.Starting with Windows 8, you can use the Get-NetAdapter cmdlet.

Use registry to see ICMP type settings

I would like to see which ICMP types are allowed / enabled on my system.
I've found this where you can set up your ICMP but is there a possibility to see these settings in registry or to get them through powershell commands?
Use Get-NetFirewallRule to enumerate the firewall rules. Use Get-NetFirewallPortFilter to get details about what these rules are filtering. Filter the output for ICMP protocol rules, then select the ICMP type.
Get-NetFirewallRule -Enabled True -Action Allow |
Get-NetFirewallPortFilter |
Where-Object { $_.Protocol -in 'icmpv4', 'icmpv6' } |
Select-Object -Expand IcmpType -Unique
Replace Allow with Block to enumerate blocking rules.
If Get-NetFirewallRule can't find a rule it will throw an error. You can suppress that by adding -ErrorAction SilentlyContinue to the command.
Note that the *-NetFirewall* cmdlets were introduced with Windows Server 2012 and are not available in earlier versions. For those you need to work with the netsh command. Use something like this to enumerate firewall rules
netsh advfirewall firewall show rule all
and parse the output for the relevant information.

how to change a disabled network adapter configuration by powershell

I want to changed an networking adapter ip address. For some security reason, we should change it when it is disabled.
I used the following:
Set-NetIPAddress -InterfaceAlias "Ethernet 3" -PrefixLength 20 -IPAddress 10.91.62.201
But that failed with following message:
Set-NetIPAddress : No matching MSFT_NetIPAddress objects found by CIM query for instances of the ROOT/StandardCimv2/MSFT_NetIPAddress class on the CIM
server: SELECT * FROM MSFT_NetIPAddress WHERE ((IPAddress LIKE '10.91.62.201')) AND ((InterfaceAlias LIKE 'Ethernet 3'))
Is there anyone who know how to changed a disabed networking adapter configuration. Thanks.
You can update it through the registry:
Get the adapter object (We need the GUID as the registry identifies the adapters by guid):
$adapter = Get-WmiObject Win32_NetworkAdapter | WHERE {$_.DeviceID -eq "1"}
Update the registry accordingly:
New-ItemProperty -Path "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\$($adapter.guid)" -Name IPAddress -Value "10.91.62.201" -Force

Resources