dsccommunity / xPSDesiredStateConfiguration

DSC resources for configuring common operating systems features, files and settings.
https://dsccommunity.org
MIT License
199 stars 132 forks source link

xPackage: Event with source identifier 'LogPath' does not exist. #767

Open billings7 opened 3 months ago

billings7 commented 3 months ago

Problem description

When using xPackage to install with an exe, with a LogPath specified, after the installation is complete the resource can fail with the error "Event with source identifier 'LogPath' does not exist.". I believe this happens when the exe does not actually output anything.

Verbose logs

VERBOSE: [server-name]: LCM:  [ Start  Resource ]  [[xPackage]InstallVSRemoteDebugger]
VERBOSE: [server-name]: LCM:  [ Start  Test     ]  [[xPackage]InstallVSRemoteDebugger]
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] The path extension was '.exe'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Perform operation 'Enumerate CimInstances' with following parameters, ''namespaceName' = root\cimv2,'className' = Win32_OperatingSystem'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Operation 'Enumerate CimInstances' complete.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Ensure is 'Present'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Product installation cannot be determined
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] product as boolean is 'False'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] The package 'VSRemoteDebugger' is not installed.
VERBOSE: [server-name]: LCM:  [ End    Test     ]  [[xPackage]InstallVSRemoteDebugger]  in 0.2030 seconds.
VERBOSE: [server-name]: LCM:  [ Start  Set      ]  [[xPackage]InstallVSRemoteDebugger]
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] The path extension was '.exe'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Perform operation 'Enumerate CimInstances' with following parameters, ''namespaceName' = root\cimv2,'className' = Win32_OperatingSystem'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Operation 'Enumerate CimInstances' complete.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Ensure is 'Present'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Product installation cannot be determined
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] product as boolean is 'False'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] The package 'VSRemoteDebugger' is not installed.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] The path extension was '.exe'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Package configuration starting.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Create log file.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Download the media over HTTP or HTTPS.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Creating cache location.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Need to download file from 'https', destination will be
'C:\ProgramData\Microsoft\Windows\PowerShell\Configuration\BuiltinProvCache\DSC_xPackageResource\VSRemoteDebugger-17.0.34606.255.exe'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Creating the destination cache file.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Creating the 'https' stream.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Setting default credential.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Getting the 'https' response stream.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Copying the 'https' stream bytes to the disk cache.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Redirecting package path to cache file location.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] The binary is an EXE.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] User has requested logging, need to attach event handlers to the process.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Starting 'C:\ProgramData\Microsoft\Windows\PowerShell\Configuration\BuiltinProvCache\DSC_xPackageResource\VSRemoteDebugger-17.0.34606.255.exe' with
'/quiet /norestart /log "C:\Logs\DSC\InstallVSRemoteDebugger.log" /quiet /norestart'.
VERBOSE: [server-name]:                            [[xPackage]InstallVSRemoteDebugger] Starting process
'C:\ProgramData\Microsoft\Windows\PowerShell\Configuration\BuiltinProvCache\DSC_xPackageResource\VSRemoteDebugger-17.0.34606.255.exe' with arguments '/quiet /norestart /log "C:\Logs\DSC\InstallVSRemoteDebugger.log" /quiet /norestart'.
VERBOSE: [server-name]: LCM:  [ End    Set      ]  [[xPackage]InstallVSRemoteDebugger]  in 69.3450 seconds.
PowerShell DSC resource DSC_xPackageResource  failed to execute Set-TargetResource functionality with error message: The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to
Stop: Event with source identifier 'C:\Logs\DSC\InstallVSRemoteDebugger.out.log' does not exist.
    + CategoryInfo          : InvalidOperation: (:) [], CimException
    + FullyQualifiedErrorId : ProviderOperationExecutionFailure
    + PSComputerName        : localhost

DSC configuration

Configuration ConfigName
{
    $ErrorActionPreference = 'Stop'

    Import-DscResource -ModuleName xPSDesiredStateConfiguration

    $adminCred = Get-AutomationPSCredential 'Admin'

    Node $AllNodes.NodeName
    {
        xPackage InstallVSRemoteDebugger {
            Name            = 'VSRemoteDebugger'
            ProductId       = ''
            Path            = 'https://blob-storage-url-here.exe'
            RunAsCredential = $adminCred
            Arguments       = '/quiet /norestart /log "C:\Logs\DSC\InstallVSRemoteDebugger.log"'
            LogPath         = 'C:\Logs\DSC\InstallVSRemoteDebugger.out.log'
        }
    }
}

Suggested solution

Replace the Get-Event calls here with something like:

$masterEvents = @(Get-Event | where SourceIdentifier -in $LogPath, $errorLogPath)
$masterEvents = $masterEvents | Sort-Object -Property TimeGenerated

Operating system the target node is running

OsName               : Microsoft Windows Server 2022 Datacenter Azure Edition
OsOperatingSystemSKU : 407
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 20348.1.amd64fre.fe_release.210507-1500
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell version and build the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.20348.2227
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.20348.2227
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

xPSDesiredStateConfiguration version

Name                         Version Path
----                         ------- ----
xPSDesiredStateConfiguration 9.1.0   C:\Program Files\WindowsPowerShell\Modules\xPSDesiredStateConfiguration\9.1.0\xPSDesiredStateConfiguration.psd1