diff --git a/tasks/version_powershell.ps1 b/tasks/version_powershell.ps1 index eedd45a59..03094bf0c 100644 --- a/tasks/version_powershell.ps1 +++ b/tasks/version_powershell.ps1 @@ -1,14 +1,16 @@ -if (Test-Path 'HKLM:\SOFTWARE\Puppet Labs\Puppet') { - $reg = $(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Puppet Labs\Puppet') - if (Test-Path $reg.RememberedInstallDir64) { +$rootPath = 'HKLM:\SOFTWARE\Puppet Labs\Puppet' + +$reg = Get-ItemProperty -Path $rootPath -ErrorAction SilentlyContinue +if ($null -ne $reg) { + if ($null -ne $reg.RememberedInstallDir64) { $loc = $reg.RememberedInstallDir64+'VERSION' - } elseif (Test-Path $reg.RememberedInstallDir) { + } elseif ($null -ne $reg.RememberedInstallDir) { $loc = $reg.RememberedInstallDir+'VERSION' } } -if ($loc -ne $null) { - Write-Output "{`"version`":`"$(type $loc)`",`"source`":`"$($loc.replace('\', '/'))`"}" +if ( ($null -ne $loc) -and (Test-Path -Path $loc) ) { + Write-Output "{`"version`":`"$(Get-Content -Path $loc -ErrorAction Stop)`",`"source`":`"$($loc.replace('\', '/'))`"}" } else { Write-Output '{"version":null,"source":null}' }