From ba608164829ed9ce07a4c3324ecc100527411f24 Mon Sep 17 00:00:00 2001 From: Mayyhem <30671833+Mayyhem@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:17:34 -0400 Subject: [PATCH] Added get admins command to list SCCM admin users --- Program.cs | 36 ++++++++++++++++++++++++++++++++++++ Properties/AssemblyInfo.cs | 4 ++-- RELEASE_NOTES.md | 4 ++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Program.cs b/Program.cs index 72fad0a..6220446 100644 --- a/Program.cs +++ b/Program.cs @@ -127,6 +127,42 @@ static void Main(string[] args) rootCommand.Add(getCommand); getCommand.AddGlobalOption(new Option(new[] { "--site-code", "-sc" }, "The three character site code (e.g., PS1) (default: the site code of the client running SharpSCCM)")); + // get admins + var getAdmins = new Command("admins", "Get information on SCCM administrators and security roles from an SMS Provider via WMI\n" + + " Permitted security roles:\n" + + " - Any (SMS Admins local group)"); + getCommand.Add(getAdmins); + getAdmins.Add(new Option(new[] { "--count", "-c" }, "Returns the number of rows that match the specified criteria")); + getAdmins.Add(new Option(new[] { "--id", "-i" }, "A string to search for in collection CollectionIDs (returns all collections where the CollectionID contains the provided string)")); + getAdmins.Add(new Option(new[] { "--name", "-n" }, "A string to search for in collection names (returns all collections where the collections name contains the provided string)")); + getAdmins.Add(new Option(new[] { "--order-by", "-o" }, "An ORDER BY clause to set the order of data returned by the query (e.g., \"Name DESC\") (default: ascending (ASC) order)")); + getAdmins.Add(new Option(new[] { "--properties", "-p" }, "Specify this option for each property to query (e.g., \"-p Name -p MemberCount\"") { Arity = ArgumentArity.OneOrMore }); + getAdmins.Add(new Option(new[] { "--sms-provider", "-sms" }, "The IP address, FQDN, or NetBIOS name of the SMS Provider to connect to (default: the current management point of the client running SharpSCCM)")); + getAdmins.Add(new Option(new[] { "--verbose", "-v" }, "Display all class properties and their values")); + getAdmins.Add(new Option(new[] { "--where-condition", "-w" }, "A WHERE condition to narrow the scope of data returned by the query (e.g., \"Name='collection0'\" or \"Name LIKE '%collection%'\")")); + getAdmins.Add(new Option(new[] { "--dry-run", "-z" }, "Display the resulting WQL query but do not connect to the specified server and execute it")); + getAdmins.Handler = CommandHandler.Create( + (string smsProvider, string siteCode, bool count, string id, string name, string orderBy, string[] properties, bool verbose, string whereCondition, bool dryRun) => + { + if (!string.IsNullOrEmpty(id)) + { + whereCondition = $"AdminID LIKE '%{id}%'"; + } + else if (!string.IsNullOrEmpty(name)) + { + whereCondition = $"LogonName LIKE '%{name}%'"; + } + if (properties.Length == 0 && !verbose) + { + properties = new[] { "AdminID", "AdminSid", "DisplayName", "LogonName", "RoleNames", "SourceSite" }; + } + ManagementScope wmiConnection = MgmtUtil.NewWmiConnection(smsProvider, null, siteCode); + if (wmiConnection != null && wmiConnection.IsConnected) + { + MgmtUtil.GetClassInstances(wmiConnection, "SMS_Admin", null, count, properties, whereCondition, orderBy, dryRun, verbose, printOutput: true); + } + }); + // get applications var getApplications = new Command("applications", "Get information on applications from an SMS Provider via WMI\n" + " Permitted security roles:\n" + diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index e79ca49..ecac5e7 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -27,5 +27,5 @@ // Minor Version // Revision // -[assembly: AssemblyVersion("2.0.9")] -[assembly: AssemblyFileVersion("2.0.9")] +[assembly: AssemblyVersion("2.0.10")] +[assembly: AssemblyFileVersion("2.0.10")] diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d024a51..b2c1546 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,5 +1,9 @@ # SharpSCCM Release Notes +### Version 2.0.10 (April 15, 2024) +##### Changes +- Added get admins command to list SCCM admin users + ### Version 2.0.9 (April 15, 2024) ##### Changes - Added option to deobfuscate a secret string offline