microsoft / MSLab

Azure Stack HCI, Windows 10 and Windows Server rapid lab deployment scripts
MIT License
1.2k stars 288 forks source link

deploy.ps1 throws an error when enabling guest service interface on a non English Hyper-V Host #422

Closed GeriOnline closed 3 years ago

GeriOnline commented 3 years ago

When deploy.ps1 is running on a non English Hyper-V host and tries to enable the guest service interface of a vm (EnableGuestServiceInterface=$true in LabConfig.ps1) an error is thrown that the requested component does not exist.

Reason: deploy.ps1 tries to enable the guest service interface by name:

Enable-VMIntegrationService -Name "Guest Service Interface"

However the name depends on the language of the Hyper-V Host - in German for example it is named "Gastdienstschnittstelle".

Suggestion: What do you think of an implementation similar to the one in the xVMHyper-V DSC resource where the guest service interface is referenced by its ID and not by name. In my experience this works for all languages of Hyper-V hosts (Windows 10, Server 2016, Server 2019 and also in the latest Server 2022 Insider Preview).

    #Enable Guest services on all VMs if integration component if configured
    if ($labconfig.EnableGuestServiceInterface){
        WriteInfo "`t Enabling Guest Service Interface"
        # Get-VM -VMName "$($labconfig.Prefix)*" | Where-Object {$_.state -eq "Running" -or $_.state -eq "Off"} | Enable-VMIntegrationService -Name "Guest Service Interface"
        $vms = Get-VM -VMName "$($labconfig.Prefix)*" | Where-Object {$_.state -eq "Running" -or $_.state -eq "Off"} 
        foreach ($vm in $vms) {
            $guestServiceId = 'Microsoft:{0}\6C09BB55-D683-4DA0-8931-C9BF705F6480' -f $vm.Id
            $guestService = $vm | Get-VMIntegrationService | Where-Object -FilterScript {$_.Id -eq $guestServiceId}
            $guestService | Enable-VMIntegrationService
        }
        $TempVMs=Get-VM -VMName "$($labconfig.Prefix)*" | Where-Object {$_.state -ne "Running" -and $_.state -ne "Off"}
        if ($TempVMs){
            WriteInfoHighlighted "`t`t Following VMs cannot be configured, as the state is not running or off"
            $TempVMs.Name
        }
    }
jaromirk commented 3 years ago

Like this? https://github.com/microsoft/WSLab/commit/9f472e097856880dea18ef51e2ee4f2949961e80#diff-e43be9f19cc769590511f212adc19adfc22a535057134221adc821e2363fedad

GeriOnline commented 3 years ago

Hi Jaromir that's exactly the location in deploy.ps1. It would be great if you would commit this in one of the next upcoming releases. Thank you Gerhard

jaromirk commented 3 years ago

Cool! I merged it to master. New version will be built right away...