Advertisement
PureGremlin

Get-VMMacAddress

Dec 22nd, 2022 (edited)
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-VMMacAddress {
  2. param ($mac)
  3. if ($mac -match "([0-9A-Fa-f]{4}[-.:]){2}([0-9A-Fa-f]{4})") {
  4.     #change 4.4.4 format to 2:2:2:2:2:2
  5.     $mactemp = $mac.Replace("-","").Replace(".","").Replace(":","")
  6.     for ($i=$mactemp.Length -2 ; $i -gt 0 ;$i=$i-2){$mactemp=$mactemp.insert($i,":")}
  7.     $mac = $mactemp
  8.     }
  9. if ($mac -match "([0-9A-Fa-f]{2}[-.]){5}([0-9A-Fa-f]{2})") {
  10.     #replace 2-2-2-2-2-2 format to 2:2:2:2:2:2
  11.     $mac = $mac.Replace("-",":")    }
  12. $vm=Get-VM | Get-NetworkAdapter | Where {$_.MacAddress -eq $mac}
  13. $vm | Select-Object Parent,Name,MacAddress
  14. }
  15.  
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement