AL hosts file access denied, hyperv unable to find virtual machine
Description
Everytime I launch install-lab I got error message hosts file denied, then hyperve can't find virtual machine.
Expected behavior
The script should run through without error
Actual behavior
Shows error messages and doesn't install the VM
Paste exceptions or verbose output in an output block.
Steps to reproduce
# Please add all PowerShell Code necessary to reproduce your issue here.
#
```PS C:\Windows\System32> Install-Lab -Verbose
VERBOSE: [11:45:59][Write-LogFunctionEntry] Install-Lab Entering... (Verbose=True)
VERBOSE: [11:45:59][Write-LogFunctionEntry] Get-LabVM Entering... )
VERBOSE: [11:45:59][Write-LogFunctionEntry] Get-LabVM Entering... (All=True,IncludeLinux=True)
VERBOSE: [11:45:59][Write-LogFunctionEntry] Update-LabMemorySettings Entering... )
VERBOSE: [11:45:59][Write-LogFunctionEntry] Get-LabVM Entering... (All=True,IncludeLinux=True)
VERBOSE: [11:45:59][Write-LogFunctionExit] Update-LabMemorySettings...leaving...(Time elapsed: 00:00:00:001)
VERBOSE: [11:45:59][Write-ScreenInfo] Creating virtual networks
Creating virtual networks
11:45:59|00:05:09|00:00:00.000| - Creating Hyper-V virtual network 'GettinStarted'
11:45:59|00:05:09|00:00:00.111| - The network switch 'GettinStarted' already exists, no changes will be made to configuration
VERBOSE: [11:45:59][Write-ScreenInfo] Done
VERBOSE: [11:45:59][Write-ScreenInfo] 11:45:59|00:05:09|00:00:00.118| - Done
11:45:59|00:05:09|00:00:00.118| - Done
VERBOSE: [11:45:59][Write-LogFunctionEntry] Get-LabVM Entering... (All=True)
VERBOSE: [11:45:59][Write-ScreenInfo] done
VERBOSE: [11:45:59][Write-ScreenInfo] 11:45:59|00:05:09|00:00:00.123| - done
11:45:59|00:05:09|00:00:00.123| - done
VERBOSE: [11:45:59][Write-ScreenInfo] Creating base images
VERBOSE: [11:45:59][Write-ScreenInfo] 11:45:59|00:05:09|00:00:00.000| - Creating base images
11:45:59|00:05:09|00:00:00.000| - Creating base images
11:45:59|00:05:09|00:00:00.007| - All base images were created previously
VERBOSE: [11:46:00][Write-ScreenInfo] Done
VERBOSE: [11:46:00][Write-ScreenInfo] 11:46:00|00:05:10|00:00:01.299| - Done
11:46:00|00:05:10|00:00:01.299| - Done
VERBOSE: [11:46:00][Write-ScreenInfo] done
VERBOSE: [11:46:00][Write-ScreenInfo] 11:46:00|00:05:10|00:00:01.302| - done
11:46:00|00:05:10|00:00:01.302| - done
VERBOSE: [11:46:00][Write-LogFunctionEntry] Get-LabVM Entering... (All=True,IncludeLinux=True)
VERBOSE: [11:46:00][Write-ScreenInfo] Creating Additional Disks
VERBOSE: [11:46:00][Write-ScreenInfo] 11:46:00|00:05:10|00:00:00.000| - Creating Additional Disks
11:46:00|00:05:10|00:00:00.000| - Creating Additional Disks
VERBOSE: [11:46:02][Write-ScreenInfo] Done
VERBOSE: [11:46:02][Write-ScreenInfo] 11:46:02|00:05:12|00:00:01.802| - Done
11:46:02|00:05:12|00:00:01.802| - Done
VERBOSE: [11:46:02][Write-ScreenInfo] Creating VMs
VERBOSE: [11:46:02][Write-ScreenInfo] 11:46:02|00:05:12|00:00:00.000| - Creating VMs
11:46:02|00:05:12|00:00:00.000| - Creating VMs
Out-File: C:\Program Files\WindowsPowerShell\Modules\HostsFile\5.22.0\HostsFile.psm1:244
Line |
244 | $hostContent | Out-File -FilePath $script:hostFilePath
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Access to the path 'C:\WINDOWS\System32\drivers\etc\hosts' is denied.
VERBOSE: [11:46:02][Write-LogFunctionEntry] Get-LabVM Entering... (Role=RootDC)
VERBOSE: [11:46:02][Write-ScreenInfo] Installing Root Domain Controllers
VERBOSE: [11:46:02][Write-ScreenInfo] 11:46:02|00:05:12|00:00:00.000| - Installing Root Domain Controllers
11:46:02|00:05:12|00:00:00.000| - Installing Root Domain Controllers
VERBOSE: [11:46:02][Write-LogFunctionEntry] Get-LabVM Entering... (Role=RootDC)
VERBOSE: [11:46:02][Write-ScreenInfo] Machines with RootDC role to be installed: 'FirstServer'
VERBOSE: [11:46:02][Write-ScreenInfo] 11:46:02|00:05:12|00:00:00.004| - Machines with RootDC role to be installed: 'FirstServer'
11:46:02|00:05:12|00:00:00.004| - Machines with RootDC role to be installed: 'FirstServer'
11:46:02|00:05:12|00:00:00.016| - Waiting for machines to start upGet-VM: C:\Program Files\WindowsPowerShell\Modules\AutomatedLabWorker\5.22.0\AutomatedLabWorkerVirtualMachines.psm1:1376
Line |
1376 | $vms = Get-VM -Name $ComputerName
| ~~~~~~~~~~~~~~~~~~~~~~~~~~
| Hyper-V was unable to find a virtual machine with name "FirstServer".
OperationStopped: C:\Program Files\WindowsPowerShell\Modules\AutomatedLabWorker\5.22.0\AutomatedLabWorkerVirtualMachines.psm1:956
Line |
956 | throw $ex
| ~~~~~~~~~
| Could not start Hyper-V machine 'FirstServer': Hyper-V was unable to find a virtual machine with name "FirstServer".
<!-- Required -->
## Environment details
<!-- Ideally, if you can: Upload a support package. ***Be warned, this may contain PII and confidential information***. If
in doubt, have a look at it first.
Support packages can be generated in the same PowerShell session you experience an error in with `New-PSFSupportPackage -Include All`
The support package allows us to retrieve all errors as well as all verbose messages, regardless of whether you have
used the Verbose parameter or not.
-->
PowerShell Version <!-- Required -->
```output
Please paste the output of $PSVersionTable in this output field
AutomatedLab components
Please paste the output of Get-Module AutomatedLab* -List | Select Name,Version in this output field
```PS C:\Windows\System32> Get-Module AutomatedLab* -List | Select Name,Version
Name Version
---- -------
AutomatedLab 5.22.0
AutomatedLab.Common 2.0.208
AutomatedLab.Recipe 5.22.0
AutomatedLab.Ships 5.22.0
AutomatedLabDefinition 5.22.0
AutomatedLabNotifications 5.22.0
AutomatedLabTest 5.22.0
AutomatedLabUnattended 5.22.0
AutomatedLabWorker 5.22.0
Are you running Powershell as Admin ? Elevated ? Check the permissions of said folder, try to change access to it for everyone temporarily. Right click folder - > Security Tab -> Click Edit to change permissions -> Add -> Everyone -> Check "Full Control" box.
Thanks for the comment @McxCZE. If @randrini would use AL in a non-elevated session, this is the error one gets:
01:10:03|00:00:21|00:00:20.328| - Location of LabSources folder is 'E:\LabSources'
01:10:03|00:00:21|00:00:00.000| - Auto-adding ISO files
This function needs to be called in an elevated PowerShell session.
At C:\Program Files\WindowsPowerShell\Modules\AutomatedLab\5.22.15\AutomatedLab.psm1:1496 char:9
+ throw 'This function needs to be called in an elevated PowerS ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (This function n...rShell session.:String) [], RuntimeException
+ FullyQualifiedErrorId : This function needs to be called in an elevated PowerShell session.
@randrini, can you try enabling the 'SkipHostFileModification' setting?
Set-PSFConfig -Module 'AutomatedLab' -Name SkipHostFileModification -Value $true
Running PS as an admin doesn't seems to be the solution
Need to give Set-PSFConfig -Module 'AutomatedLab' -Name SkipHostFileModification -Value $true as the command to go forward
This issue has been automatically marked as stale because it has not had activity from the community in the last 30 days. It will be closed if no further activity occurs within 10 days. If the issue is labelled with any of the work labels (e.g bug, enhancement, documentation, or tests) then the issue will not auto-close.
This issue has been automatically closed because it is has not had activity from the community in the last 40 days.