web-dev-qa-db-ja.com

PowershellDSCとモジュールxHyper-Vを使用してHyper-V VMを作成するにはどうすればよいですか?

モジュール xHyper-V を使用して、Windows10ワークステーションからHyper-V2016ホスト上にVMを作成しようとしていますが、それほど喜びはありません。

私のHyper-VホストはLithiumと呼ばれ、DSCスクリプトは以下のとおりです。

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"
        }
    }
}

マシンアカウントに共有へのアクセスを許可しましたが、ファイルコピーは正常に機能しますが、仮想ハードディスクの追加中にエラーが発生します。何か案は?

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
2
Mark Allison

問題は、ローカルパスを使用する必要があるときに、ファイル共有を使用してVHDを参照していたことでした。したがって、ドライブのセットアップは次のようになります。

    $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"
    }

正常に動作します。

4
Mark Allison