I am using an Azure runbook to run a powershell script on an Azure VM that attempts to create a simple VM on a physical Windows 2012 R2 server. Hyper-V and remote Powershell are available on the server. The directory the VM is going to be created in is for this test, shared with Everyone, full control. The Powershell call is as follows:
Import-Module Hyper-V
$session = New-PSSession -ComputerName $DeviceName -Credential $creds
$result = Invoke-Command -Session $session `
-ScriptBlock{(New-VM -Name $args[0] -Path $args[1] -MemoryStartupBytes $args[2] -NewVHDPath $args[3] -NewVHDSizeBytes $args[4] -SwitchName $args[5] )} `
-ArgumentList $VMName, $VMDirectory, $MemoryStartUpSize, $vhdPath, $vmDiskSize, $SwitchName
The account in $creds is in the list of Hyper-V Administrators on the physical server. The New-VM Cmdlet actually creates the vhdx Hard Disk Image File in the path $vhdPath. It also creates a new folder named 'Web01TestVM02' ($VMName) and a subfolder called Virtual Machines. But then I get the error message:
'Web01TestVM02' failed to add device 'Virtual Hard Disk'. (Virtual machine ID ...)
'Web01TestVM02': The Machine Account 'domainname\servername$' or the user initiating the VM management operation or both do not have the required access to the file share '\servername\e$\VirtualMachines\VMTest02\Web01TestVM02.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'
Any ideas how to solve or debug this is much appreciated.