Skip to content

Instantly share code, notes, and snippets.

@natemccurdy
Last active August 4, 2017 17:46
Show Gist options
  • Save natemccurdy/01ce84d9dc69455d439c2177bdbea5e6 to your computer and use it in GitHub Desktop.
Save natemccurdy/01ce84d9dc69455d439c2177bdbea5e6 to your computer and use it in GitHub Desktop.
# 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
@Iristyle
Copy link

@natemccurdy
Copy link
Author

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