Sometime you need to move a large number of VMs, or you need to recover from a broken hyper-v host, or similar. If you have a few VM’s, that will be easy, but if you have many you will most likely use PowerShell to import the VM’s. That works perfectly fine, but you have a few VM’s that did weren’t imported correctly you will end in a state when you ask your self –Which VM’s are imported and which ones are not?
(You can download the script from GitHub: https://github.com/DeploymentBunny/Files/tree/master/Tools/Get-VIAUnimportedvmcxFiles )
Find the not yet imported VM configurations
That will of course be done using PowerShell, and here is the function that I use
Function Get-VIAUnimportedvmcxFiles
{
<#
.Synopsis
Script used find not yet imported Hyper-V Configurations
.DESCRIPTION
Created: 2016-11-07
Version: 1.0
Author : Mikael Nystrom
Twitter: @mikael_nystrom
Blog : http://deploymentbunny.com
Disclaimer: This script is provided "AS IS" with no warranties.
.EXAMPLE
Get-VIAUnimportedvmcxFiles
#>
[CmdletBinding(SupportsShouldProcess=$true)]
Param(
[string]$Folder
)
if((Test-Path -Path $Folder) -ne $true){
Write-Warning "I'm sorry, that folder does not exist"
Break
}
$VMsIDs = (Get-VM).VMId
$VMConfigs = (Get-ChildItem -Path $Folder -Filter *.vmcx -Recurse).BaseName
$obj = Compare-Object -ReferenceObject $VMsIDs -DifferenceObject $VMConfigs
$Configs = foreach($Item in ($obj.InputObject)){
$Items = Get-ChildItem -Path $Folder -Recurse -File -Filter *.vmcx | Where-Object -Property Basename -Like -Value "*$Item"
$Items | Where-Object -Property FullName -NotLike -Value "*Snapshots*"
}
Return $Configs.FullName
}
/mike
Categories: Hyper-V, PowerShell



