2014-02-26 19:12:24 +00:00
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
[string]$VmId
|
2014-02-15 23:29:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Include the following modules
|
2014-02-26 19:12:24 +00:00
|
|
|
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
|
|
|
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
2014-02-15 23:29:16 +00:00
|
|
|
|
2015-11-23 20:05:37 +00:00
|
|
|
$ip_address = ""
|
2014-02-26 19:12:24 +00:00
|
|
|
$vm = Get-VM -Id $VmId -ErrorAction "Stop"
|
2015-11-23 20:05:37 +00:00
|
|
|
$networks = Get-VMNetworkAdapter -VM $vm
|
|
|
|
foreach ($network in $networks) {
|
|
|
|
if ($network.IpAddresses.Length -gt 0) {
|
|
|
|
$ip_address = $network.IpAddresses[0]
|
|
|
|
if (-Not ([string]::IsNullOrEmpty($ip_address))) {
|
|
|
|
# We found our IP address!
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-26 19:12:24 +00:00
|
|
|
$resultHash = @{
|
2014-02-15 23:29:16 +00:00
|
|
|
ip = "$ip_address"
|
|
|
|
}
|
2014-02-26 19:12:24 +00:00
|
|
|
$result = ConvertTo-Json $resultHash
|
|
|
|
Write-Output-Message $result
|