Home > database >  Loop through array to check for the correct name using Get-NetAdapter
Loop through array to check for the correct name using Get-NetAdapter

Time:04-20

Recently I put a script together that will collect some data from a computer. While extracting this data some of it is being sorted by name.

$BTMacAdress = $(Get-NetAdapter -Name "Bluetooth Network Connection").MacAddress

When you use this script on a Spanish machine the name will change to "Conexión de red Bluetooth".

I have created an array with all the connection names in different languages. How can I make it so it will loop through the array and check if the correct name is in this array?

I tried to put the array in place of "Bluetooth Network Connection" but that had little succes.

CodePudding user response:

Filter by media type

Get-NetAdapter | where PhysicalMediaType -eq "Bluetooth"

This of course also works the way you're using it:

$BTMacAdress = (Get-NetAdapter | where PhysicalMediaType -eq "Bluetooth").MacAddress
  • Related