Sha256: a4fd7732ff340d4b28fcfec578f6b739a9aab79b212fd391e64b72baee8d071f

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

Param(
    [Parameter(Mandatory=$true)]
    [string]$VmId
 )

# Include the following modules
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))

$vm = Get-VM -Id $VmId -ErrorAction "Stop"
$networks = Get-VMNetworkAdapter -VM $vm
foreach ($network in $networks) {
  if ($network.IpAddresses.Length -gt 0) {
    foreach ($ip_address in $network.IpAddresses) {
      if ($ip_address.Contains(".")) {
        $ip4_address = $ip_address
      } elseif ($ip_address.Contains(":")) {
        $ip6_address = $ip_address
      }
      if (-Not ([string]::IsNullOrEmpty($ip4_address)) -Or -Not ([string]::IsNullOrEmpty($ip6_address))) {
        # We found our IP address!
        break
      }
    }
  }
}

if (-Not ([string]::IsNullOrEmpty($ip4_address))) {
  $guest_ipaddress = $ip4_address
} elseif (-Not ([string]::IsNullOrEmpty($ip6_address))) {
  $guest_ipaddress = $ip6_address
}

if (-Not ([string]::IsNullOrEmpty($guest_ipaddress))) {
  $resultHash = @{
      ip = $guest_ipaddress
  }
  $result = ConvertTo-Json $resultHash
  Write-Output-Message $result
} else {
  Write-Error-Message "Failed to determine IP address"
}

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
vagrant-unbundled-2.0.1.0 plugins/providers/hyperv/scripts/get_network_config.ps1
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/plugins/providers/hyperv/scripts/get_network_config.ps1
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/plugins/providers/hyperv/scripts/get_network_config.ps1
vagrant-unbundled-2.0.0.1 plugins/providers/hyperv/scripts/get_network_config.ps1
vagrant-unbundled-1.9.8.1 plugins/providers/hyperv/scripts/get_network_config.ps1