By referencing the smsclictr.automation.dll this functionality can be reused to build workflow activities/batch programs that calls the same logic as SCCM client center uses. Example code:
SMSClient client = new SMSClient(computerName);
client.Connection.Connect();
if (client.Connection.mScope.IsConnected)
{
//Connect to the clients managementPoint SQL server
SqlConnectionStringBuilder sqlConnectionBuilder = new SqlConnectionStringBuilder("Integrated Security=True");
sqlConnectionBuilder.DataSource = client.ManagementPoint;
sqlConnectionBuilder.InitialCatalog = "SMS_" + client.SiteCode;
SqlConnection sqlConnection = new SqlConnection(sqlConnectionBuilder.ToString());
try
{
sqlConnection.Open();
SqlCommand command = new SqlCommand();
command.CommandText = "SELECT PolicyID, Body FROM Policy WHERE (PolicyID LIKE '%" + advertisementID + "%') ORDER BY PolicyID";
command.Connection = sqlConnection;
SqlDataReader dataReader = command.ExecuteReader();
while (dataReader.Read())
{
byte[] policyBody = dataReader[1] as byte[];
client.SoftwareDistribution.ImportSCCMPolicy(policyBody, false);
Logging.Log("Policy imported on computer '" + computerName + "' (AdvertisementID: " + advertisementID + ")", System.Diagnostics.EventLogEntryType.Information);
break;
}
sqlConnection.Close();
}
catch (Exception ex)
{
Logging.Log("Failed to get policy from SQL for advertisement '" + advertisementID + "'. Error: " + ex.ToString(), System.Diagnostics.EventLogEntryType.Error);
}
}
Very nice, it's very usefull! May I ask You, how could I use the SCCM Client center's dll to start remote processes?
ReplyDeleteRegards,
Csontikka
Hi Csontikka!
DeleteI haven't tried to do that through the SCCM Client Center dll. Have you looked at psexec (sysinternals) for starting remote processes?
/Tomas
Unfortunatelly all the incoming ports are closed expect of the port of the SCCM. This is why bexec and psexec are not options for me :(
ReplyDeleteGreat job, nice one it is very beneficial for regulars, i also take many more decision about SCCM @ sccm client center
ReplyDeleteis it possible to import a local policy for a software deployment with Configuration Manager Current Branch
ReplyDeleteI mean a import a local policy related to an existing software update deployment
ReplyDelete