diff --git a/Program.cs b/Program.cs index 3fed6a1..2919ca2 100644 --- a/Program.cs +++ b/Program.cs @@ -71,7 +71,7 @@ static void Main(string[] args) execCommand.Add(new Option(new[] { "--user", "-u" }, "The UniqueUserName of the user to execute an application as or receive NTLM authentication from (e.g., \"APERTURE\\cave.johnson\")")); execCommand.Add(new Option(new[] { "--site-code", "-sc" }, "The three character site code (e.g., \"PS1\") (default: the site code of the client running SharpSCCM)")); execCommand.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)")); - execCommand.Add(new Option(new[] { "--wait-time", "-w" }, "The time (in seconds) to wait for the deployment to execute before cleaning up (default: 120)")); + execCommand.Add(new Option(new[] { "--wait-time", "-w" }, () => 120, "The time (in seconds) to wait for the deployment to execute before cleaning up (default: 120)")); execCommand.Handler = CommandHandler.Create( (string device, string collectionId, string collectionName, string path, string relayServer, string resourceId, bool runAsSystem, string collectionType, string user, int waitTime, string smsProvider, string siteCode) => { @@ -92,7 +92,7 @@ static void Main(string[] args) ManagementScope wmiConnection = MgmtUtil.NewWmiConnection(smsProvider, null, siteCode); if (wmiConnection != null && wmiConnection.IsConnected) { - SmsProviderWmi.Exec(wmiConnection, collectionId, collectionName, device, path, relayServer, resourceId, !runAsSystem, collectionType, user, waitTime = 120); + SmsProviderWmi.Exec(wmiConnection, collectionId, collectionName, device, path, relayServer, resourceId, !runAsSystem, collectionType, user, waitTime); } } }); diff --git a/lib/SmsProviderWmi.cs b/lib/SmsProviderWmi.cs index 56a7a2f..019afe6 100644 --- a/lib/SmsProviderWmi.cs +++ b/lib/SmsProviderWmi.cs @@ -11,7 +11,11 @@ public static class SmsProviderWmi { public static void Exec(ManagementScope wmiConnection, string collectionId = null, string collectionName = null, string deviceName = null, string applicationPath = null, string relayServer = null, string resourceId = null, bool runAsUser = true, string collectionType = null, string userName = null, int waitTime = 120) { - ManagementObject collection = GetCollection(wmiConnection, collectionName, collectionId); + ManagementObject collection = null; + if (!string.IsNullOrEmpty(collectionName) || !string.IsNullOrEmpty(collectionId)) + { + collection = GetCollection(wmiConnection, collectionName, collectionId); + } // Create a collection is one is not specified if (collection == null) { @@ -1022,7 +1026,7 @@ public static ManagementObject NewCollectionMember(ManagementScope wmiConnection try { collection.InvokeMethod("AddMembershipRule", addMembershipRuleParams, null); - Console.WriteLine($"[+] Added {matchingResource["Name"]} {matchingResource["ResourceID"]} to {(!string.IsNullOrEmpty(collectionName) ? collectionName : collectionId)}"); + Console.WriteLine($"[+] Added {matchingResource["Name"]} ({matchingResource["ResourceID"]}) to {(!string.IsNullOrEmpty(collectionName) ? collectionName : collectionId)}"); Console.WriteLine($"[+] Waiting for new collection member to become available..."); bool memberAvailable = false; while (!memberAvailable)