tabs-not-spaces / intune.hv.tools Goto Github PK
View Code? Open in Web Editor NEWA set of tools to assist with the creation of Intune managed virtual machines in Hyper-V.
License: GNU General Public License v3.0
A set of tools to assist with the creation of Intune managed virtual machines in Hyper-V.
License: GNU General Public License v3.0
When use New-ClientVM create VMs, if authentication failed, it still continue create VM without autopilot json file. I was expecting it should return error and stop create VM. :)
Private function New-ClientDevice
uses existing HGS Guardian for creating a key protector, but does not do a check for whether or not one exists, nor does it create one.
Suggestion is to add this after line 42:
If (!$owner)
{
# Creating new UntrustedGuardian since it did not exist
$owner = New-HgsGuardian -Name UntrustedGuardian –GenerateCertificates
}
If the function fails, the VHDX file is locked because it's left Mounted
I would suggest adding a Finally
block and moving the Dismount-VHD lines to it:
function Publish-AutoPilotConfig {
[cmdletBinding()]
param (
[parameter(Position = 1, Mandatory = $true)]
[string]$VMName,
[parameter(Position = 2, Mandatory = $true)]
[string]$ClientPath
)
try {
Write-Host "Mounting $VMName.vhdx.. " -ForegroundColor Cyan -NoNewline
$disk = (Mount-VHD -Path "$ClientPath\$VMName.vhdx" -Passthru | Get-Disk | Get-Partition | Where-Object { $_.type -eq 'Basic' }).DriveLetter
if ($disk) {
Write-Host $script:tick -ForegroundColor Green
Write-Host "Publishing Autopilot config to $VMName`.vhdx.. " -ForegroundColor Cyan -NoNewline
$AutopilotFolder = "$disk`:\Windows\Provisioning\Autopilot"
IF(!(Test-path -Path $AutopilotFolder -PathType Container)){
New-Item -Path $AutopilotFolder -ItemType Directory -Force
}
Copy-Item -path "$ClientPath\AutopilotConfigurationFile.json" -Destination "$AutopilotFolder\AutopilotConfigurationFile.json" -Force
}
}
catch {
throw "Error occurred during config publish.."
}
Finally{
Write-Host $script:tick -ForegroundColor Green
Write-Host "Dismounting $VMName.vhdx " -ForegroundColor Cyan -NoNewline
Dismount-VHD "$ClientPath\$VMName.vhdx"
Write-Host $script:tick -ForegroundColor Green
Write-Host "Config published successfully to $ClientPath\$VMName.vhdx..`n" -ForegroundColor Green
}
}
the JSON file is not accepted for starting the autopilot process. It's created in UTF8 format. It needs to be in ASCII or ANSI format.
https://docs.microsoft.com/en-us/windows/deployment/windows-autopilot/existing-devices
When trying to add image based on ISO I receive the error message:
Building reference image..Convert-WindowsImage: Cannot validate argument on parameter 'Edition'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
The command does not prompt me to choose the correct edition
I'm using PS 7.1.3 (x64) and tried different ISO's but with same error message
ISO's come from myvisualstudio URL
en_windows_10_business_editions_version_21h1_x64_dvd_ec5a76c1.iso
en_windows_10_business_editions_version_20h2_updated_march_2021_x64_dvd_c2f10533.iso
en_windows_10_business_editions_version_2004_updated_april_2021_x64_dvd_6ffb5872.iso
The code uses the stripped object that only contains the displayname, it should use the original object returned from Intune
If you compare to the result of converting the actual object from Intune, the result is very different
It would be nice that the HW hash from the VM(s) is uploaded automatically in to your tenant for a complete Autopilot enrollment. Now I have to upload the HW hash manually.
I would find it helpful if there was a switch to enable dynamic memory during the creation of the VMs.
When using the parent function New-ClientVM
and allowing it to Auto-publish the Autopilot config, the Private function Publish-AutopilotConfig
throws an error:
PS C:\Program Files\WindowsPowerShell\Modules\Intune.HV.Tools\1.0.0.203\Private> Publish-AutoPilotConfig -VMName $vmParams.VMName -ClientPath $vmParams.ClientPath
Mounting Tenant_1.vhdx..
Publishing Autopilot config to Tenant_1.vhdx.. Error occurred during config publish..
At C:\Program Files\WindowsPowerShell\Modules\Intune.HV.Tools\1.0.0.203\Private\Publish-AutoPilotConfig.ps1:25 char:9
+ throw "Error occurred during config publish.."
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Error occurred during config publish..:String) [], RuntimeException
+ FullyQualifiedErrorId : Error occurred during config publish..
When manually testing the Copy-Item
on line 16:
PS C:\Program Files\WindowsPowerShell\Modules\Intune.HV.Tools\1.0.0.203\Private> Copy-Item -path "$ClientPath\AutopilotConfigurationFile.json" -Destination "$disk`:\Windows\Provisioning\Autopilot\AutopilotConfigurationFile.json" -Force
Copy-Item : Could not find a part of the path 'F:\Windows\Provisioning\Autopilot\AutopilotConfigurationFile.json'.
At line:1 char:13
+ Copy-Item -path "$ClientPath\AutopilotConfigurationFile.j ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Copy-Item], DirectoryNotFoundException
+ FullyQualifiedErrorId : System.IO.DirectoryNotFoundException,Microsoft.PowerShell.Commands.CopyItemCommand
Digging into the Copy-Item function, does not appear to be able to force-create missing folders in the destination path. If I manually create the missing folder \Autopilot
, the function works successfully.
Suggested edit:
Add this lines just before Line 16 to ensure the folders exist in the mounted VHD
$AutopilotFolder = "$disk`:\Windows\Provisioning\Autopilot"
IF(!(Test-path -Path $AutopilotFolder -PathType Container)){
New-Item -Path $AutopilotFolder -ItemType Directory -Force
}
Please convert all write-host to write-Verbose. Write-host means I can't Capture any of the output that your cmdlet displays.
When I use TenantName "InTuneTraining987" and create 2x VMs in sequence, the resulting HyperV VM's are named:
When I use TenantName "TestTraining" and create 2x VMs in sequence, the resulting HyperV VM's are named:
Could this be a bug that affects any TenantName that ends in a numeric value?
When trying to create the images I am getting the issue below originally, adjusted the user account to be in the Hyper-V admin group and the "required permission error is gone" but still receiving the RefVHDX issue.
PS C:\Users\user> New-ClientVM -TenantName 'COMPANY' -NumberOfVMs 3 -CPUsPerVM 2 -VMMemory 16gb
Grabbing Autopilot config..
Autopilot Configuration file found locally: c:\IntuneTesting\.hvtools\tenantVMs\COMPANY\AutopilotConfigurationFile.json
Get-VM: C:\Users\user\Documents\PowerShell\Modules\Intune.HV.Tools\1.0.0.312\Public\New-ClientVM.ps1:92
Line |
92 | $max = ((Get-VM -Name "$TenantName*").name -replace " …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~
| You do not have the required permission to complete this task. Contact the administrator of the
| authorization policy for the computer 'DESKTOP-VF3HK2I'.Creating VM: COMPANY_1..
WARNING: Cannot process argument transformation on parameter 'RefVHDX'. Cannot convert value to type System.String.
OS-Windows 10 Pro - 21H1
PS-Major Minor Build Revision
----- ----- ----- --------
7 2 1 -1
https://stackoverflow.com/questions/60600539/powershell-5-cannot-convert-value-to-system-string This seems like it explains the issue but I cant work it out.
Fix:
Changed code in Get-AutopilotPolicy to require Microsoft.Graph.Authentication and removed code if in 7 to run modules in 5
Option to add unattended.xml to vhdx. For almost unattended installations for testing
Hi,
when I try to run the add-imagetoconfig cmdlet I receive this error: Building reference image..Write-Error: The media is write protected. (Exception from HRESULT: 0x80070013)
It will let me to choose the image name of the ISO, but then the write error popsup.
Add-ImageToConfig -ImageName Windows11 -IsoPath .\images\Win11_22H2_English_x64v2.iso =
Mount-DiskImage: C:\Users\LabAdmin\Documents\PowerShell\Modules\Intune.HV.Tools\1.0.0.312\Private\New-ClientVHDX.ps1:29
Line |
29 | Mount-DiskImage -ImagePath $winIso | Out-Null
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| The system cannot find the path specified.
WARNING: The filename, directory name, or volume label syntax is incorrect.
If I follow your instructions, I will stick to the following point:
PS C:\Users\h.eichmeyer> New-ClientVM -TenantName 'henetsystems' -OSBuild 2004 -NumberOfVMs 1 -CPUsPerVM 5 -VMMemory 8gb
Grabbing Autopilot config..
Creating VM: henetsystems_1..
WARNING: Cannot process argument transformation on parameter 'RefVHDX'. Cannot convert value to type System.String.
PS C:\Users\h.eichmeyer>
Somehow I manged to run a command twice so I ended up with two tenantconfig with the same name and values.
Without any warning or error. Next when I ran the New-ClientVM command I received an
"Warning: Cannot bind argument to parameter 'Path' because it is null"
When cleaning up the duplacte TenantConfig from the hvconfig.json all was good :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.