Exemple #1
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            SCCMServer = settings.SCCMSERVER;
            userName   = settings.UserName;
            password   = settings.Password;

            String machineName   = request.Inputs["Machine Name"].AsString();
            String variableName  = request.Inputs["Variable Name"].AsString();
            String variableValue = request.Inputs["Variable Value"].AsString();
            String machineSite   = String.Empty;


            String resourceID = String.Empty;

            if (request.Inputs.Contains("Machine Site"))
            {
                machineSite = request.Inputs["Machine Site"].AsString();
            }
            if (request.Inputs.Contains("Resource ID"))
            {
                resourceID = request.Inputs["Resource ID"].AsString();
            }
            //Setup WQL Connection and WMI Management Scope
            WqlConnectionManager connection = CMInterop.connectSCCMServer(SCCMServer, userName, password);

            using (connection)
            {
                //Get Computer Object
                IResultObject computerObj = null;

                IResultObject col = null;
                if (resourceID.Equals(String.Empty))
                {
                    col = CMInterop.getSCCMComputer(connection, "", machineName, "");
                }
                else
                {
                    col = CMInterop.getSCCMComputer(connection, resourceID, "", "");
                }

                foreach (IResultObject c in col)
                {
                    computerObj = c;
                    if (computerObj != null)
                    {
                        if (machineSite.Equals(String.Empty))
                        {
                            String SiteCode = determineComputerSiteCode(computerObj);
                            CMInterop.createSCCMComputerVariable(connection, SiteCode, variableName, variableValue, false, computerObj["ResourceID"].IntegerValue);
                        }
                        else
                        {
                            CMInterop.createSCCMComputerVariable(connection, machineSite, variableName, variableValue, false, computerObj["ResourceID"].IntegerValue);
                        }

                        response.Publish("Variable Name", variableName);
                        response.Publish("Variable Value", variableValue);
                        response.Publish("Machine Name", machineName);
                    }
                    else
                    {
                        response.LogErrorMessage("Could not find machine " + machineName);
                    }
                }
            }
        }