Como criar uma VM do Hyper-V com o Powershell DSC e o módulo xHyper-V?

3

Estou tentando criar uma VM no host do Hyper-V 2016 a partir da minha estação de trabalho do Windows 10 usando o módulo xHyper-V sem muita alegria.

Meu host do Hyper-V chama-se Lithium e meu script DSC está abaixo.

Configuration EndToEndXHyperV_RunningVM
{
    param
    (
        [string[]]$NodeName = 'lithium',

        [Parameter(Mandatory)]
        [string]$VMName,

        [Parameter(Mandatory)] 
        [string]$StartupMemory,

        [Parameter(Mandatory)]
        [string]$MinimumMemory,

        [Parameter(Mandatory)]
        [string]$MaximumMemory,

        [Parameter(Mandatory)]
        [String]$SwitchName,

        [Parameter(Mandatory)]
        [Uint32]$ProcessorCount,

        [ValidateSet('Off','Paused','Running')]
        [String]$State = 'Off',

        [Switch]$WaitForIP
    )

    Import-DscResource –ModuleName 'PSDesiredStateConfiguration'
    Import-DscResource -module xHyper-V

    Node $NodeName
    {
        $NewSystemVHDPath = "\lithium\VHDs-SSD\$($VMName)-System.vhdx"

        # Copy VHD File - hard coded to Windows 2016 Core Eval for now
        File SystemDisk {
            SourcePath = "\lithium\Templates\Windows 2016 Core Template\System.vhdx"
            DestinationPath = $NewSystemVHDPath      
            Type = "File"
            Ensure = "Present"
        }

        # create the generation 2 testVM out of the vhd.
        xVMHyperV NewVM
        {
            Ensure          = 'Present'
            Name            = $VMName
            VhdPath         = $NewSystemVHDPath
            SwitchName      = $SwitchName
            State           = $State
            Path            = $Path
            Generation      = 2
            StartupMemory   = $StartupMemory
            MinimumMemory   = $MinimumMemory
            MaximumMemory   = $MaximumMemory
            ProcessorCount  = $ProcessorCount
            RestartIfNeeded = $true
            WaitForIP       = $WaitForIP 
            DependsOn       = "[File]SystemDisk"
        }
    }
}

Eu concedi acesso à conta da máquina aos compartilhamentos e a cópia do arquivo funciona bem, mas recebo um erro ao adicionar o disco rígido virtual. Alguma idéia?

PS C:\Repos\Infrastructure\DSC> Start-DscConfiguration -Path .\EndToEndXHyperV_RunningVM -Wait -Verbose -Force 
VERBOSE: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namesp
aceName' = root/Microsoft/Windows/DesiredStateConfiguration'.
VERBOSE: An LCM method call arrived from computer COWSLIP with user sid S-1-5-21-1075642099-280362434-2919291742-1105.
VERBOSE: [LITHIUM]: LCM:  [ Start  Set      ]
VERBOSE: [LITHIUM]: LCM:  [ Start  Resource ]  [[File]SystemDisk]
VERBOSE: [LITHIUM]: LCM:  [ Start  Test     ]  [[File]SystemDisk]
VERBOSE: [LITHIUM]:                            [[File]SystemDisk] The system cannot find the file specified.
VERBOSE: [LITHIUM]:                            [[File]SystemDisk] The related file/directory is: \lithium\VHDs-SSD\test-System.vhdx.
VERBOSE: [LITHIUM]:                            [[File]SystemDisk] Building file list from cache.
VERBOSE: [LITHIUM]: LCM:  [ End    Test     ]  [[File]SystemDisk]  in 0.0510 seconds.
VERBOSE: [LITHIUM]: LCM:  [ Start  Set      ]  [[File]SystemDisk]
VERBOSE: [LITHIUM]:                            [[File]SystemDisk] The system cannot find the file specified.
VERBOSE: [LITHIUM]:                            [[File]SystemDisk] The related file/directory is: \lithium\VHDs-SSD\test-System.vhdx.
VERBOSE: [LITHIUM]:                            [[File]SystemDisk] Building file list from cache.
VERBOSE: [LITHIUM]:                            [[File]SystemDisk] Copying file \lithium\Templates\Windows 2016 Core Template\System.vhdx to \lithium\VHDs-SSD\test-Sy
stem.vhdx.
VERBOSE: [LITHIUM]: LCM:  [ End    Set      ]  [[File]SystemDisk]  in 17.2540 seconds.
VERBOSE: [LITHIUM]: LCM:  [ End    Resource ]  [[File]SystemDisk]
VERBOSE: [LITHIUM]: LCM:  [ Start  Resource ]  [[xVMHyperV]NewVM]
VERBOSE: [LITHIUM]: LCM:  [ Start  Test     ]  [[xVMHyperV]NewVM]
VERBOSE: [LITHIUM]: LCM:  [ End    Test     ]  [[xVMHyperV]NewVM]  in 1.0200 seconds.
VERBOSE: [LITHIUM]: LCM:  [ Start  Set      ]  [[xVMHyperV]NewVM]
VERBOSE: [LITHIUM]:                            [[xVMHyperV]NewVM] Checking if VM 'test' exists ...
VERBOSE: [LITHIUM]:                            [[xVMHyperV]NewVM] VM 'test' does not exist.
VERBOSE: [LITHIUM]:                            [[xVMHyperV]NewVM] Creating VM 'test' ...
Failed to add device 'Virtual Hard Disk'.
The Machine Account 'DUCK\LITHIUM$' or the user initiating the VM management operation or both do not have the required access to the file share 
'\lithium\VHDs-SSD\test-System.vhdx'.  Please ensure that the computer machine account and the user initiating the VM management operation have full access to the 
file share as well as the file system folder backing the file share.  Error: 'General access denied error'
'test' failed to add device 'Virtual Hard Disk'. (Virtual machine ID 4DE01C38-E027-4366-B56A-85B527BB34CB)
'test': The Machine Account 'DUCK\LITHIUM$' or the user initiating the VM management operation or both do not have the required access to the file share 
'\lithium\VHDs-SSD\test-System.vhdx'.  Please ensure that the computer machine account and the user initiating the VM management operation have full access to the 
file share as well as the file system folder backing the file share.  Error: 'General access denied error' (0x80070005). (Virtual machine ID 
4DE01C38-E027-4366-B56A-85B527BB34CB)
    + CategoryInfo          : PermissionDenied: (:) [], CimException
    + FullyQualifiedErrorId : AccessDenied,Microsoft.HyperV.PowerShell.Commands.NewVM
    + PSComputerName        : lithium
    
por Mark Allison 06.12.2016 / 20:13

1 resposta

4

O problema era que eu estava usando um compartilhamento de arquivos para fazer referência ao VHD, quando deveria ter usado um caminho local. Então a configuração para as unidades é agora:

    $NewSystemVHDPath = "E:\VHDs\$($VMName)-System.vhdx"

    # Copy VHD File - hard coded to Windows 2016 Core Eval for now
    File SystemDisk {
        SourcePath = "D:\Templates\Windows 2016 Core Template\System.vhdx"
        DestinationPath = $NewSystemVHDPath      
        Type = "File"
        Ensure = "Present"
    }

Funciona bem.

    
por 06.12.2016 / 20:58