From ebd77eeaed23f2cdf4fb06382fdabc83a01dbe92 Mon Sep 17 00:00:00 2001 From: Dan Hutchings Date: Wed, 25 May 2022 18:00:37 -0700 Subject: [PATCH] Refactor logged_on_user_sid to support Windows Server 2019 In its current state, the returns on Windows Server 2019 because the is searching for a registry value that doesn't exist in that version of the operating system. To fix this, the code is being refactored to use PowerShell command to retrieve the SID of the current logged in user. --- itchef/cookbooks/cpe_helpers/libraries/cpe_helpers.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/itchef/cookbooks/cpe_helpers/libraries/cpe_helpers.rb b/itchef/cookbooks/cpe_helpers/libraries/cpe_helpers.rb index 1d58b0eb..47d7c70e 100644 --- a/itchef/cookbooks/cpe_helpers/libraries/cpe_helpers.rb +++ b/itchef/cookbooks/cpe_helpers/libraries/cpe_helpers.rb @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. # - +include Chef::Mixin::PowershellOut module CPE class Helpers LOGON_REG_KEY = @@ -269,7 +269,8 @@ def self.last_logged_on_user_from_registry end def self.logged_on_user_sid - logged_on_user_registry['LastLoggedOnUserSID'] + ps_cmd = "Get-LocalUser -Name \"#{logged_on_user_name}\" | Select-Object SID | % { $_.SID.Value }" + powershell_out(ps_cmd).stdout.strip end def self.ldap_lookup_script(username)