Powershell import VM in Hyper-V Server

 

Пробуем просто импортировать каталог с ВМ.  Как видно из примера ниже - это не работает на прямую.

PS C:\Corefig> Import-VM -Path 'C:\VM\Trassir\Virtual Machines\F3338EDA-31FC-4A65-8196-C13FF999BB00.xml'
Import-VM : Unable to import virtual machine due to configuration errors.  Please use Compare-VM to repair the virtual machine.
At line:1 char:1
+ Import-VM -Path 'C:\VM\Trassir\Virtual Machines\F3338EDA-31FC-4A65-81 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-VM], VirtualizationException
    + FullyQualifiedErrorId : OperationFailed,Microsoft.HyperV.PowerShell.Commands.ImportVM
1.png

 Сначала нужно подготовить конфигурацию к импорту. Проверяем считывается ли она в принципе.

PS C:\Corefig> Compare-VM -Path 'C:\VM\Trassir\Virtual Machines\F3338EDA-31FC-4A65-8196-C13FF999BB00.xml'
Output:
VM                 : VirtualMachine (Name = 'Trassir') [Id = 'f3338eda-31fc-4a65-8196-c13ff999bb00']
OperationType      : ImportVirtualMachine
Destination        : MGA-NODE01-MICR
Path               : C:\VM\Trassir\Virtual Machines\F3338EDA-31FC-4A65-8196-C13FF999BB00.xml
SnapshotPath       : C:\VM\Trassir\Snapshots
VhdDestinationPath : C:\VM\Trassir\Virtual Hard Disks
VhdSourcePath      :
Incompatibilities  : {33012}
CheckpointPath     : C:\VM\Trassir\Snapshots
 
Запоминаем конфигурацию ВМ в переменную $report
PS C:\Corefig> $report = Compare-VM -Path 'C:\VM\Trassir\Virtual Machines\F3338EDA-31FC-4A65-8196-C13FF999BB00.xml'
PS C:\Corefig> $report.Incompatibilities | Format-Table -AutoSize
Output:
Message                               MessageId Source
-------                               --------- ------
Could not find Ethernet switch 'WAN'.     33012 VMNetworkAdapter (Name = 'Network Adapter', VMName = 'Trassir') [VMI...
 
 Отключаем устаревший виртуальный свич и проверяем что получилось.
PS C:\Corefig> $report.Incompatibilities[0].Source | Disconnect-VMNetworkAdapter
PS C:\Corefig>  Compare-VM -CompatibilityReport $report
 
Output:
VM                 : VirtualMachine (Name = 'Trassir') [Id = 'f3338eda-31fc-4a65-8196-c13ff999bb00']
OperationType      : ImportVirtualMachine
Destination        : MGA-NODE01-MICR
Path               : C:\VM\Trassir\Virtual Machines\F3338EDA-31FC-4A65-8196-C13FF999BB00.xml
SnapshotPath       : C:\VM\Trassir\Snapshots
VhdDestinationPath : C:\VM\Trassir\Virtual Hard Disks
VhdSourcePath      :
Incompatibilities  : {}
CheckpointPath     : C:\VM\Trassir\Snapshots
 
 Импортируем ВМ. 
PS C:\Corefig> import-vm -CompatibilityReport $report
Output:
Name    State CPUUsage(%) MemoryAssigned(M) Uptime   Status             Version
----    ----- ----------- ----------------- ------   ------             -------
Trassir Off   0           0                 00:00:00 Operating normally 5.0
 
Проверяем 
PS C:\Corefig> get-vm
Output:
Name    State CPUUsage(%) MemoryAssigned(M) Uptime   Status             Version
----    ----- ----------- ----------------- ------   ------             -------
Trassir Off   0           0                 00:00:00 Operating normally 5.0


Img:
2.png

 
Подключаем новый виртуальный свич lan.
 PS C:\Corefig>  Get-VMNetworkAdapter -VMName Trassir | Connect-VMNetworkAdapter -SwitchName lan
Output:
3.png
Была ли эта статья полезной?
Пользователи, считающие этот материал полезным: 1 из 1
Еще есть вопросы? Отправить запрос

0 Комментарии

Войдите в службу, чтобы оставить комментарий.
На базе технологии Zendesk