cloudbase / windows-imaging-tools

Tools to automate the creation of a Windows image for OpenStack, supporting KVM, Hyper-V, ESXi and more.
Apache License 2.0
680 stars 227 forks source link

Could not retrieve VM runtime logs #352

Open oott123 opened 3 years ago

oott123 commented 3 years ago

The code here is using Get-VMIntegrationService $Name -Name "Key-Value Pair Exchange").Enabled to check if KV pair exchange service is enabled.

However, when you are using a non-English locale of Windows, you will get other names like 键值对交换 (in chinese):

image

And it throws a error when getting by name:

# Get-VMIntegrationService WindowsOnlineImage-Sysprep354251398 -Name "Key-Value Pair Exchange"
Get-VMIntegrationService : 找不到具有给定名称的集成组件。
所在位置 行:1 字符: 1
+ Get-VMIntegrationService WindowsOnlineImage-Sysprep354251398 -Name "K ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-VMIntegrationService],VirtualizationException
    + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.GetVMIntegrationService

which will cause "Could not retrieve VM runtime logs"

So I think we should remove the integration service enabled check in order to retrive the log correctly:

--- a/WinImageBuilder.psm1
+++ b/WinImageBuilder.psm1
@@ -1158,8 +1158,7 @@ function Wait-ForVMShutdown {
         $vmState = (Get-VM -Name $Name).State
         $isOff =  $vmState -eq "Off"
         try {
-            if ($vmState -ne "Running" -or `
-                !(Get-VMIntegrationService $Name -Name "Key-Value Pair Exchange").Enabled) {
+            if ($vmState -ne "Running") {
                 continue
             }
             $currentVMMessages = Get-KVPData -VMName $Name
MrEasy commented 2 years ago

can confirm the same issue when buildong on a German Win11. Your change resolves it.

tatsushid commented 1 year ago

If it needs to keep the integration service check, it can be done like the following I think

--- a/WinImageBuilder.psm1
+++ b/WinImageBuilder.psm1
@@ -1195,7 +1197,7 @@ function Wait-ForVMShutdown {
         $isOff =  $vmState -eq "Off"
         try {
             if ($vmState -ne "Running" -or `
-                !(Get-VMIntegrationService $Name -Name "Key-Value Pair Exchange").Enabled) {
+                !(Get-VMIntegrationService $Name | Where-Object Id -Match "2A34B1C2-FD73-4043-8A5B-DD2159BC743F").Enabled) {
                 continue
             }
             $currentVMMessages = Get-KVPData -VMName $Name

The ID value is described at MicrosoftDocs/azure-docs#52634