diff --git a/Invoke-OpenSSHConfiguration.ps1 b/Invoke-OpenSSHConfiguration.ps1 index add746b..fd09eaf 100644 --- a/Invoke-OpenSSHConfiguration.ps1 +++ b/Invoke-OpenSSHConfiguration.ps1 @@ -491,14 +491,16 @@ Switch (Test-ProcessElevationStatus) { {($_ -eq $True)} { - #Check if user's registry hive is loaded under HKEY_USERS - $UserRegistryBasePath = "Registry::HKEY_USERS\$($CurrentUserSession.SID)" + #Check if user's profile/registry hive is loaded via Win32_UserProfile + $UserProfile = Get-CimInstance -ClassName 'Win32_UserProfile' -Filter "SID = '$($CurrentUserSession.SID)'" -ErrorAction SilentlyContinue -Verbose:$False - Switch (Test-Path -Path $UserRegistryBasePath -ErrorAction SilentlyContinue) + Switch (($Null -ine $UserProfile) -and ($UserProfile.Loaded -eq $True)) { {($_ -eq $True)} { - $WriteLogMessage.Invoke(0, @("Accessing certificate store for session user: $($CurrentUserSession.NTAccount) [SID: $($CurrentUserSession.SID)]")) + $UserRegistryBasePath = "Registry::HKEY_USERS\$($CurrentUserSession.SID)" + + $WriteLogMessage.Invoke(0, @("Accessing certificate store for session user: $($CurrentUserSession.NTAccount) [SID: $($CurrentUserSession.SID)] [Profile Loaded: $($UserProfile.Loaded)]")) #Read certificates directly from user's registry hive $UserCertStoreNames = @('Root', 'CA') @@ -542,7 +544,7 @@ Switch (Test-ProcessElevationStatus) Default { - $WriteLogMessage.Invoke(1, @("User registry hive not loaded for SID: $($CurrentUserSession.SID). Skipping user certificates.")) + $WriteLogMessage.Invoke(1, @("User profile not loaded for SID: $($CurrentUserSession.SID) (Win32_UserProfile.Loaded = $($UserProfile.Loaded)). Skipping user certificates.")) } } }