Always create $env:USERPROFILE\.hvtoolscfgpath
When use this function initialize a new folder, it didn't update "$env:USERPROFILE.hvtoolscfgpath" file content, or recreate this new file, so reads hvconfig.json configuration from wrong folder. I think "$env:USERPROFILE.hvtoolscfgpath" file need to be updated when run this function.
In my example, I first run " Initialize-HVTools -Path "D:\Hyper-V\DEMO1", when want to use a new folder by using Initialize-HVTools -Path "D:\Hyper-V\DEMO", it reads hvconfig.json path from .hvtoolscfgpath, which it goes to the DEMO1 folder, not DEMO folder.
PS C:\Windows\system32> Initialize-HVTools -Path "D:\Hyper-V\DEMO" Add-ImageToConfig -ImageName "2004" -IsoPath "D:\No-Dedup\Asennus\ISO\en_windows_10_business_editions_version_2004_updated_june_2020_x64_dvd_cc9defea.iso" Add-TenantToConfig -TenantName "Contoso" -ImageName "2004" -AdminUpn "[email protected]" Add-NetworkToConfig -VSwitchName 'CrazyNet' New-ClientVM -TenantName 'Contoso' -NumberOfVMs 1 -CPUsPerVM 1 -VMMemory 2gb -Verbose Creating hvtools folder structure..
- Creating D:\Hyper-V\DEMO.hvtools\hvconfig.json.. √ (Already created - no need to run this again..) Adding 2004 to config.. √ Creating reference Autopilot VHDX - this may take some time.. Select an Image from the below available options:
ImageIndex ImageName
1 Windows 10 Education
2 Windows 10 Education N
3 Windows 10 Enterprise
4 Windows 10 Enterprise N
5 Windows 10 Pro
6 Windows 10 Pro N
7 Windows 10 Pro Education
8 Windows 10 Pro Education N
9 Windows 10 Pro for Workstations
10 Windows 10 Pro N for Workstations
Select Image Index..(1..10): 3 Image 3 / Windows 10 Enterprise selected..
Building reference image..√
Adding Contoso to config.. √
Adding virtual switch details to config.. √
VERBOSE: Autopilot Reference VHDX:
VERBOSE: Client name: Contoso
VERBOSE: Win10 ISO is located:
VERBOSE: Path to client VMs will be: D:\Hyper-V\DEMO1.hvtools\tenantVMs\Contoso
VERBOSE: Number of VMs to create: 1
VERBOSE: Admin user for Contoso is: [email protected] [email protected]
WARNING: Cannot bind argument to parameter 'Path' because it is null.
@sandytsang I'd suggest that unless you specifically specify reset, you shouldn't ever really use the initialize cmdlet. What we could do is check when the cmdlet runs:
- is there already a .hvToolsCfgPath file?
- does the path in the file resolve?
if it does, return a message to the user saying that configuration is already found.
we can then replace the "reset" switch with "force" that will allow us to forcefully re-initialize the environment.
Thoughts?
Let me know if you want to give this a go - otherwise I'm happy to implement it.
The "reset" switch sound good! Good job guys, can't wait to test it again!