I'm using PowerShell to edit an XML file. What I'm doing is searching for a string and replacing that string within the XML. The command for this looks like:
(Get-Content "C:\My_VM\Virtual Machines\xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.XML") |
Foreach-Object {$_ -replace "My_VMName", "My_VMName_0"} |
Set-Content "C:\My_VM\Virtual Machines\xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.XML"
Where the XML file in my case is a Virtual Machine image to be imported into Hyper-V
The find/replace works fine, and I can rename the .vhdx file for the import no problem also. I do this using:
Rename-Item "C:\My_VM\Virtual Hard Disks\My_VMName.vhdx" My_VMName_0.vhdx
But when I try to use Import-VM using the following cmdlet:
Import-VM -Path "C:\My_VM\Virtual Machines\xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx.XML" -Copy -GenerateNewID
I get the error:
"Import-VM : The virtual machine configuration could not be read. The data might be corrupt or not valid."
Does anyone know why this is? I've already come up with a workaround(using different technologies) but it's still frustrating. If I open a text editor and rename everything manually it works fine.