Creating Random MAC Addresses

by May 17, 2017

If you just need a bunch of randomly generated MAC addresses, and you don’t care much about whether these addresses are actually valid, then here is a one liner:

 
PS> (0..5 | ForEach-Object { '{0:x}{1:x}' -f (Get-Random -Minimum 0 -Maximum 15),(Get-Random -Minimum 0 -Maximum 15)})  -join ':'

a5:66:07:6d:d9:18

PS> (0..5 | ForEach-Object { '{0:x}{1:x}' -f (Get-Random -Minimum 0 -Maximum 15),(Get-Random -Minimum 0 -Maximum 15)})  -join ':'

3c:c8:4e:e3:75:6c
 

Add it to a loop, and you get as many MAC addresses as you need:

 
PS> 0..100 | ForEach-Object { (0..5 | Foreach-Object { '{0:x}{1:x}' -f (Get-Random -Minimum 0 -Maximum 15),(Get-Random -Minimum 0 -Maximum 15)})  -join ':' }

bc:38:3a:91:a9:79
36:55:3a:a0:3d:c4
6d:2c:91:ae:01:35
ec:01:11:42:a7:09
e7:0b:24:d3:14:1d
(...)
 

Twitter This Tip! ReTweet this Tip!