vagrant/plugins/providers/hyperv/scripts/get_network_mac.ps1

33 lines
758 B
PowerShell
Raw Normal View History

2018-05-24 16:57:55 +00:00
#Requires -Modules VagrantMessages
param(
[Parameter(Mandatory=$true)]
[string]$VmId
2018-05-24 16:57:55 +00:00
)
2018-05-24 16:57:55 +00:00
$ErrorActionPreference = "Stop"
2018-05-24 16:57:55 +00:00
try {
$ip_address = ""
$vm = Hyper-V\Get-VM -Id $VmId
$networks = Hyper-V\Get-VMNetworkAdapter -VM $vm
foreach ($network in $networks) {
if ($network.MacAddress -gt 0) {
$mac_address = $network.MacAddress
if (-Not ([string]::IsNullOrEmpty($mac_address))) {
# We found our mac address!
break
}
}
}
2018-05-24 16:57:55 +00:00
$resultHash = @{
mac = "$mac_address"
}
$result = ConvertTo-Json $resultHash
Write-Output-Message $result
} catch {
Write-Error-Message "Unexpected error while fetching MAC: ${PSItem}"
exit 1
}