private int CreateDevice(string strDeviceName, string strDeviceMacadress, string strLimtitingCollectionID)
        {
            try
            {
                if (strDeviceName == null && strDeviceMacadress == null)
                {
                    throw new ArgumentNullException("DeviceName or MACAdress most be defined");
                }

                SmsNamedValuesDictionary namedValues = new SmsNamedValuesDictionary();
                WqlConnectionManager connection = new WqlConnectionManager(namedValues);
                connection.Connect("CM01"); 

                Dictionary<string, object> newDevice2 = new Dictionary<string, object>();

                newDevice2.Add("NetbiosName", strDeviceName);
                newDevice2.Add("SMBIOSGUID", null); // For Future things
                newDevice2.Add("MACAddress", strDeviceMacadress);
                newDevice2.Add("OverwriteExistingRecord", false);

                // Create CM Device to site database
                IResultObject outParam = connection.ExecuteMethod("SMS_Site", "ImportMachineEntry", newDevice2);

                if (string.IsNullOrEmpty(strLimtitingCollectionID) == false)
                {
                    IResultObject collection = connection.GetInstance("SMS_Collection.collectionID='" + strLimtitingCollectionID + "'");
                    IResultObject collectionRule = connection.CreateEmbeddedObjectInstance("SMS_CollectionRuleDirect");
                    collectionRule["ResourceClassName"].StringValue = "SMS_R_SYSTEM";
                    collectionRule["ResourceID"].IntegerValue = outParam["ResourceID"].IntegerValue;

                    Dictionary<string, object> inParam2 = new Dictionary<string, object>();
                    inParam2.Add("collectionRule", collectionRule);

                    // Add Device to specified collection. Empty will automatcally add device to All Systems
                    collection.ExecuteMethod("AddMemberShipRule", inParam2);
                }

                return outParam["ResourceID"].IntegerValue;
            }
            catch (SmsException e)
            {
                Console.WriteLine("Failed to add the computer. " + e.Message);
                throw;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Return a single Application object
        /// </summary>
        internal static Application GetApplicationByName(string name, string server)
        {
            NamedObject.DefaultScope = "xCM";

            WqlConnectionManager connectionManager = CMConnection.Connect(server);

            IResultObject applications = connectionManager.QueryProcessor.ExecuteQuery("SELECT * FROM SMS_Application WHERE LocalizedDisplayName='" + name + "' AND IsLatest=1");

            // this should only return one result, but we need to perform a Get() to retrieve the lazy properties
            IResultObject application = null;

            foreach (IResultObject result in applications)
            {
                result.Get();
                // tip : make sure the CI_ID is not in single quotes, for example, SMS_Application.CI_ID='123456'
                application = connectionManager.GetInstance(@"SMS_Application.CI_ID=" + result["CI_ID"].IntegerValue);
            }

            ApplicationFactory applicationFactory = new ApplicationFactory();
            AppManWrapper      applicationWrapper = AppManWrapper.WrapExisting(application, applicationFactory) as AppManWrapper;

            return(applicationWrapper.InnerAppManObject as Application);
        }
Esempio n. 3
0
        public string GetBootImageSourceVersion(string packageId, string secret)
        {
            //' Validate secret key
            if (secret != secretKey)
            {
                return("A secret key was not specified or cannot be validated");
            }
            else
            {
                //' Connect to SMS Provider
                smsProvider          smsProvider = new smsProvider();
                WqlConnectionManager connection  = smsProvider.Connect(siteServer);

                try
                {
                    //' Query for Boot Image instance
                    IResultObject queryResult = connection.GetInstance("SMS_BootImagePackage.PackageID='" + packageId + "'");

                    if (queryResult != null)
                    {
                        //' Return SourceVersion property from instance
                        int sourceVersion = queryResult["SourceVersion"].IntegerValue;
                        return(sourceVersion.ToString());
                    }
                    else
                    {
                        return("Unable to find any Boot Images");
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(DateTime.Now + ": Unhandled exception occured: " + ex.ToString());
                    return("Unhandled exception occured");
                }
            }
        }