Remove characters in every item in array

Hello Everyone, So completely new on Powershell.Starting to learn it. Ik have an issue with my script. Which i cannot find how to solve it. I created an array with computer information. (ip and mac addresses).

So i can do for example $computers.mac, I get a list of mac addresses. What i need is to remove the last 9 characters of the mac address.

What i found:
$mac = $computers.mac[0]
$mac.Substring(0,$mac.length-9)

this is working, but off course just for 1 item

So, it should be something with foreach i think, but till now cannot figure it out…

ForEach ($Mac in $LocalMacAddressList)
{
{
$mac.Substring(0,$computers.length-8)
}
}

I hope someone, can point me in the right direction. Help is appriciated.

Yours, dennis

Dennis,
Welcome to the forum. :wave:t4:

That’s actually not needed. If all your MAC addresses have the same format as it’s usually is you don’t need to calculate the length for each individual element of the array. It could look like this:

$InputData = @'
ComputerName,IP,MAC
Computer01,113.104.240.40,fb-63-b7-58-f8-62
Computer02,57.48.35.201,43-59-a0-66-e2-37
Computer03,228.140.219.217,e7-8f-de-6d-ee-bf
Computer04,73.28.70.240,d7-4c-6d-7d-33-d5
Computer05,133.43.119.115,7b-5f-04-cd-03-4e
'@ |
    ConvertFrom-Csv

$InputData.MAC.substring(0,8)

And the output of this code snippet would look like this:

fb-63-b7
43-59-a0
e7-8f-de
d7-4c-6d
7b-5f-04

thank you Olaf, this is where i was looking for.