In System Center 2012 Configuration Manager, user accounts connect to site systems and Active Directory to perform various tasks. Prior to System Center 2012 Configuration Manager, the Manage Site Accounts tool (MSAC) was used to manage these user accounts. The MSAC tool has been deprecated. Using a new WMI method, these account passwords can be encrypted for a specific site. The following code snipped demonstrates how user account passwords can be encrypted for a specific site.
To Encrypt Data for a Site
-
Connect to the Configuration Manager site.
-
Get the parameters for the EncryptDataEx Method in Class SMS_Site method.
-
Add the data to be encrypted to the Data parameter.
-
Add the site code of the specific site for which the data should be encrypted to the SiteCode parameter.
-
Encrypt the data for the specified site by invoking the EncryptDataEx Method in Class SMS_Site.
-
In this case, the encrypted string is output as a test.
Example
The following example encrypts data for a specific site.
Copy Code | |
---|---|
using System; using System.Management; namespace Encryption { class Program { static void Main(string[] args) { // SMS_Site::EncryptDataEx is a class level method, // it will encrypt data for the site based on passed in site code. try { ManagementScope scope = new ManagementScope(@"root\sms\site_ABC"); ManagementClass cls = new ManagementClass(scope.Path.Path, "SMS_Site", null); // Set up input parameters. ManagementBaseObject inParams = cls.GetMethodParameters("EncryptDataEx"); inParams["Data"] = @"pass123"; // data to be encrypted inParams["SiteCode"] = @"ABC"; // encrypt the data for that specific site // Get the encrypted data. ManagementBaseObject outSiteParams = cls.InvokeMethod("EncryptDataEx", inParams, null); // print the encrypted data Console.WriteLine(outSiteParams["EncryptedData"].ToString()); } catch (ManagementException e) { Console.WriteLine("Failed to execute method {0}", e.ToString()); } } } } |
Compiling the Code
The C# example requires:
Namespaces
System
System.Management
Assembly
Robust Programming
For more information about error handling, see About Configuration Manager Errors.