Exporting Hyper-V Servers to CSV
When running a Hyper-V scan in DMC, you must provide a list of servers (hosts or guest VMs) that DMC will connect to.
The easiest way to do this is to generate a CSV file in the format that DMC expects.
This guide provides a PowerShell helper script to export running Hyper-V guest VMs into a DMC-ready CSV file.
Why this is needed¶
- Unlike VMware (which connects directly to vCenter), DMC cannot automatically enumerate Hyper-V environments.
- Instead, you must provide FQDNs or IP addresses of the machines to scan.
- The CSV export makes it easy to bulk-load this list into DMC.
Required Permissions¶
Before running the export script, ensure you have the following permissions:
Hyper-V Management Access - Hyper-V Administrator role or equivalent permissions on target hosts - Ability to enumerate VMs using PowerShell cmdlets - Access to VM network adapter information
Network Connectivity - Network access to VMs for port scanning (ports 22, 3389, 445, 5985/5986) - Firewall exceptions for outbound connections to these ports - Integration Services enabled on VMs for IP address discovery
PowerShell Environment - Execution policy allowing script execution (RemoteSigned, Unrestricted, or Bypass) - Write access to the output directory for CSV export
Required PowerShell Modules - Hyper-V module (included with Windows Server or available via RSAT tools)
CSV format required by DMC¶
host
fqdn-or-ip
- host: FQDN or IP address of the server
DMC will automatically detect the operating system during the Validate Servers step.
The script provided in this guide is supplied as-is, without any warranties or guarantees. You should validate and test the script in your own environment before running it in production or on critical systems.
Export Hyper-V Guest VMs¶
This script collects running guest VMs from a Hyper-V host and outputs their IP addresses or DNS names to a CSV.
<#
.SYNOPSIS
Export running Hyper-V VMs to DMC CSV import format.
.DESCRIPTION
- Enumerates all running VMs on the specified Hyper-V host (default Piper-V).
- Exports a CSV file (dmc_hypervimport.csv) in the same directory as the script.
- CSV contains: host (IP or DNS, per switch).
.PARAMETER HyperVHost
Hyper-V host to query.
.PARAMETER Return
Whether to return IPv4 or DNS name. Defaults to 'IPv4'.
.EXAMPLE
.\Export-HVGuests.ps1
=> Creates .\dmc_hypervimport.csv with host=IPv4
.EXAMPLE
.\Export-HVGuests.ps1 -Return DNS
=> Creates .\dmc_hypervimport.csv with host=FQDN
#>
[CmdletBinding()]
param(
[Parameter()] [string] $HyperVHost,
[Parameter()] [ValidateSet('IPv4','DNS')] [string] $Return = 'IPv4'
)
function Get-PrimaryIPv4 {
param([string[]] $IpAddresses)
if (-not $IpAddresses) { return $null }
$IpAddresses |
Where-Object { $_ -match '^\d{1,3}(\.\d{1,3}){3}$' -and ($_ -notmatch '^169\.254\.') } |
Select-Object -First 1
}
if (-not (Get-Module -ListAvailable -Name Hyper-V)) {
Write-Error "Hyper-V PowerShell module not found."
exit 1
}
try {
$vms = Get-VM -ComputerName $HyperVHost -ErrorAction Stop | Where-Object State -eq 'Running'
} catch {
Write-Error "Failed to query VMs on host '$HyperVHost': $($_.Exception.Message)"
exit 1
}
$rows = foreach ($vm in $vms) {
$ip = $null
try {
$adapters = Get-VMNetworkAdapter -VMName $vm.Name -ComputerName $HyperVHost -ErrorAction Stop
$allIps = @()
foreach ($a in $adapters) { if ($a.IPAddresses) { $allIps += $a.IPAddresses } }
$ip = Get-PrimaryIPv4 -IpAddresses $allIps
} catch { }
$hostValue = if ($Return -eq 'IPv4') {
$ip
} else {
if ($ip) {
try { ([System.Net.Dns]::GetHostEntry($ip)).HostName } catch { $vm.Name }
} else {
$vm.Name
}
}
[pscustomobject]@{
host = $hostValue
# os intentionally omitted - DMC will auto-detect
}
}
# Write output to script directory
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$outputFile = Join-Path $scriptDir "dmc_hypervimport.csv"
try {
$rows | Export-Csv -NoTypeInformation -Encoding UTF8 -Path $outputFile
Write-Host "Export complete: $outputFile"
} catch {
Write-Error "Failed to write CSV: $($_.Exception.Message)"
exit 1
}
Examples¶
Basic Usage¶
Export from Local Hyper-V Host:
.\Export-HVGuests.ps1
- Uses the local machine as the Hyper-V host
- Outputs to
.\dmc_hypervimport.csvin the current directory - Returns IPv4 addresses for discovered VMs
Export with DNS Names:
.\Export-HVGuests.ps1 -Return DNS
- Returns FQDN (Fully Qualified Domain Names) instead of IP addresses
- Useful when you prefer hostnames over IP addresses
Remote Host Export¶
Single Remote Host:
.\Export-HVGuests.ps1 -HyperVHost "HV-SERVER-01"
- Targets a specific remote Hyper-V host
- Requires appropriate permissions to access the remote host
Custom Host with DNS Names:
.\Export-HVGuests.ps1 -HyperVHost "HV-PROD-01" -Return DNS
- Targets a production Hyper-V host
- Returns DNS names for better readability
Using the CSV in DMC¶
Open Server Selection¶
In Physical Scan, go to Server Selection.
Import CSV¶
Click Import CSV and choose the exported file.
Validate Connectivity¶
Validate servers to confirm connectivity (WinRM or SSH).
Run Scan¶
Proceed with Guest Credentials → Settings → Scan → Results.
The script only exports running VMs and automatically skips VMs that are stopped or in other states. DMC will automatically detect the operating system during the Validate Servers step.
Key Features¶
- Simple and focused: Exports only running VMs with essential information
- Flexible output: Choose between IP addresses or DNS names
- Automatic filtering: Skips APIPA addresses (169.254.x.x) and stopped VMs
- Error handling: Graceful handling of network adapter access issues
- DMC optimized: Output format matches exactly what DMC expects
Troubleshooting¶
Common Issues:
- "Hyper-V PowerShell module not found": Install RSAT tools or run on a Hyper-V management host
- "Failed to query VMs": Check permissions and network connectivity to the target host
- Empty CSV: Verify VMs are running and have network adapters with IP addresses
- Missing IPs: Ensure Integration Services are enabled on VMs for IP address discovery

