2018-05-24 16:57:55 +00:00
|
|
|
#Requires -Modules VagrantMessages
|
|
|
|
|
|
|
|
param(
|
2016-10-05 11:48:48 +00:00
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
[string]$VmId
|
2018-05-24 16:57:55 +00:00
|
|
|
)
|
2016-10-05 11:48:48 +00:00
|
|
|
|
2018-05-24 16:57:55 +00:00
|
|
|
$ErrorActionPreference = "Stop"
|
2016-10-05 11:48:48 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2016-10-05 11:48:48 +00:00
|
|
|
}
|
|
|
|
|
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
|
2016-10-05 11:48:48 +00:00
|
|
|
}
|