Tuesday, January 22, 2013

Refresh Package Source Distribution points using C#


Below is the code to update Refresh Package source distribution points using C# 


 public static string RefreshPackageDPs(string pkgID)
        {
 
            string result = null;
            List<string> dpstatusinfo = new List<string>();
            try
            {

//code to connect to SCCM
               ManagementScope scope;
ConnectionOptions connOptions = new ConnectionOptions()
                                   {
                                       Username = userName,
                                       Password = userPassword,
                                       Impersonation = ImpersonationLevel.Impersonate //Identify- recommended level for WMI Calls
                                       ,
                                   };//Timeout= TimeSpan.MaxValue
                    scope = new ManagementScope(wmiNameSpace, connOptions);
 scope.Connect();

//Code to Refresh the DP's
                ObjectQuery query = new ObjectQuery("SELECT *  FROM SMS_DistributionPoint WHERE PackageID='" + pkgID + "'");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
 
 
                foreach (ManagementObject queryObj in searcher.Get())
                {   
                    queryObj.SetPropertyValue("RefreshNow", true);
                    queryObj.Put();
                }
 
                result= "All DP's refresh started successfully!";
            }
            catch (ManagementException e)
            {
                result = "An error occurred while refresh package DP's.";

            }
            return result;
        }

Leave me a comment is you need any more info 

Difference between Update Dp's and Refresh Dp's.
Refer - > http://technet.microsoft.com/en-us/library/bb892806.aspx

No comments:

Post a Comment

Devops links

  Build Versioning in Azure DevOps Pipelines