Created
August 31, 2021 15:43
-
-
Save cgorshing/b4458e243b2e231a63a7cf1437583a13 to your computer and use it in GitHub Desktop.
A custom Puppet Fact to find local accounts on a Windows Machine. The sid's will be used for HKEY_USERS\${sid}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Facter.add('local_account_sids') do | |
confine osfamily: 'Windows' | |
setcode do | |
# https://stackoverflow.com/questions/29330882/why-cant-i-include-win32-in-my-chef-recipe | |
# require 'win32/registry' | |
# include ::Win32 | |
# https://www.lifewire.com/hkey-users-2625903 | |
# Found someone reference that S-1-5-21 is only local users | |
local_user_prefix = 'S-1-5-21-' | |
exclude_postfix = '_Classes' | |
default_account = '.DEFAULT' | |
res = [] | |
::Win32::Registry.open(::Win32::Registry::HKEY_USERS, '').each_key do |subkey, wtime| | |
if subkey == default_account or | |
(subkey.start_with?(local_user_prefix) and !subkey.end_with?(exclude_postfix)) | |
res << subkey | |
end | |
end | |
res | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment