GithubHelp home page GithubHelp logo

tabs-not-spaces / intune.hv.tools Goto Github PK

View Code? Open in Web Editor NEW
61.0 61.0 18.0 493 KB

A set of tools to assist with the creation of Intune managed virtual machines in Hyper-V.

License: GNU General Public License v3.0

PowerShell 100.00%

intune.hv.tools's Issues

New-ClientDevice - No handling for empty HGS Guardian

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
    }

Publish-AutoPilotConfig - Locks VHDX file if function fails

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
    }
}

Error add-imagetoconfig

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

Publish-AutoPilotConfig - Copy-Item does not create missing subfolders

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
          }

New-ClientVM naming bug when TenantName ends in numeric value

When I use TenantName "InTuneTraining987" and create 2x VMs in sequence, the resulting HyperV VM's are named:

  • InTuneTraining987_1 (correct)
  • InTuneTraining987_9872 (should be InTuneTraining987_2).

When I use TenantName "TestTraining" and create 2x VMs in sequence, the resulting HyperV VM's are named:

  • TestTraining_1 (correct)
  • TestTraining_2 (correct).

Could this be a bug that affects any TenantName that ends in a numeric value?

Regkey is not available

I'm trying to run this tool on my Hyper-V Server 2019, but when I chooses a image, number 5 in my case, then I get an error stating that the HKLM:\Software\Microsoft\Windows NT\CurrentVersion\WinPE path is unavailable, because it doesn't exist.

image

Any advise?

New-ClientVM - 'RefVHDX'. Cannot convert value to type System.String.

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.

include unattended.xml

Option to add unattended.xml to vhdx. For almost unattended installations for testing

Write-error

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 Does not support Partial Paths

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.

Cannot process argument transformation on parameter 'RefVHDX'

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>

There is no duplicate check for TenantToConfig name

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 :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.