The Deployment Bunny

OS Deployment, Virtualization, Microsoft based Infrastructure…

  • Archives

  • Meta

PowerShell is King – Find VM Configuration files (.vmcx) that have not been imported/registered

Posted by Mikael Nystrom on November 9, 2016

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: )

Find the not yet imported VM configurations

That will of course be done using PowerShell, and here is the function that I use

Script and output.

Function Get-VIAUnimportedvmcxFiles
        Script used find not yet imported Hyper-V Configurations
        Created: 2016-11-07
        Version: 1.0
        Author : Mikael Nystrom
        Twitter: @mikael_nystrom
        Blog   :
        Disclaimer: This script is provided "AS IS" with no warranties.

    if((Test-Path -Path $Folder) -ne $true){
        Write-Warning "I'm sorry, that folder does not exist"

    $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


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: