I've been trying to create a VM on my Hyper-V 2016 host from my Windows 10 workstation using module xHyper-V with not a lot of joy.
My Hyper-V host is called Lithium and my DSC Script is below.
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"
}
}
}
I have granted the Machine account access to the shares and the file copy works fine, but I get an error adding the virtual hard disk. Any ideas?
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
The issue was I was using a file share to reference the VHD, when I should have used a local path. So the set-up for the drives is now:
Works fine.