Last active
August 4, 2017 17:46
-
-
Save natemccurdy/01ce84d9dc69455d439c2177bdbea5e6 to your computer and use it in GitHub Desktop.
This is now a module: https://forge.puppet.com/nate/windows_account_names
This file contains hidden or 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
# Custom fact that shows the current name of the Administrator and | |
# Guest accounts based on well-known SID's. | |
# | |
# http://support.microsoft.com/kb/243330 | |
# | |
require 'puppet' | |
Facter.add(:account_names) do | |
confine osfamily: :windows | |
setcode do | |
account_names = {} | |
Puppet::Type.type('user').instances.find_all do |user| | |
user_values = user.retrieve | |
# Check for the well-known admin SID. | |
account_names['Administrator'] = user.name if user_values[user.property(:uid)] =~ /^S-1-5-21.*-500$/ | |
# Check for the well-known guest SID. | |
account_names['Guest'] = user.name if user_values[user.property(:uid)] =~ /^S-1-5-21.*-501$/ | |
end | |
account_names | |
end | |
end |
Thanks for that @Iristyle
Maybe I'll refactor this to return a hash of all, or at least the common ones, of those.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full list of structures at https://msdn.microsoft.com/en-us/library/cc980032.aspx