How to re-create symlinks of VM configs in Hyper-V using PowerShell

Hyper-V keeps VM configs at %ProgramData%MicrosoftWindowsHyper-VVirtual Machines as a symlink to the original location.

You may get them broken due to various reasons, e.g.:

  • Server disaster
  • Upgrade to next version of OS/Hyper-V and then rollback
  • Migration

To restore functioning you need to create a symlink for each xml config, i.e.:

mklink %ProgramData%MicrosoftWindowsHyper-VVirtual Machines{guid}.xml d:MyVMVirtual Machines{guid}.xml

But how to automate this if you have tens of VMs? Here’s the command:


Get-ChildItem -Recurse *.xml | New-Symlink -LiteralPath { Join-Path -Path '%ProgramData%MicrosoftWindowsHyper-VVirtual Machines' -ChildPath $_.Name } -TargetPath { $_.FullName }

This entry was posted in Infrastructure and tagged , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s