This question comes up quite often – “How do I get additional AD properties into the Service Manager CMDB?” Like this , or this , or this . These properties might be either properties which exist in AD that we don’t sync in by default with the out of box AD connector OR they might be AD schema extension properties that a customer has added to AD.
In this blog post, I’m going to show you how you can create an automated AD connector that runs on a schedule that does the following:
This particular process can be slightly modified to create all kinds of “connectors”. For example:
To fully understand this example, please read up on the CSV import process first if you haven’t already. I definitely recommend trying out a few of the examples so you get the feel for it.
For this particular example, this is what we are going to do:
1) Using the techniques describe in the previous post on Deriving and Extending Classes we need to create a management pack that extends the System.Domain.User class to add a new property for storing the user’s web page address. This property exists in AD out of the box, but we don’t sync it in as part of the out-of-the-box AD connector in Service Manager. This could just as well be a custom property that you have created in AD.
Here is our class extension to add the WWWHomePage property to the System.Domain.User class:
<ClassType ID="Microsoft.Demo.AD.Extension.Connector" Accessibility="Public" Abstract="false" Base="System!System.Domain.User" Hosted="false" Singleton="false" Extension="true">
<Property ID="WWWHomePage" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="2000" MinLength="0" Required="false" MinValue="-2147483648" MaxValue="2147483647" />
</ClassType>
Don’t forget to put in the DisplayStrings !
2) Next, we need to create our workflow so we open up this management pack in the Service Manager Authoring Console. Do this by launching the Authoring Console and then File –> Open and point to the MP .xml file.
3) Right click on the Workflows node in the MP explorer and choose Create.
4) In the first page of the workflow wizard provide a rule name and click Next.
5) On the next page, select Timer for the trigger condition and click next:
6) On the next page, enter the schedule you want to use and click Next:
7) On the next page, provide a name for the workflow and click Next:
😎 On the next page, click Create:
9) And finally, Close.
10) Now, drag a PowerShell script activity from the Toolbox onto the design surface:
11) Select the PowerShell script activity and do two things in the Properties pane
a) enter the Script server name – this is the FQDN of the Service Manager management server in this case.
Note: if you start from the management pack I provide in the attachment to this blog post, please make sure you change the server name by opening the MP in the authoring console and recompile the workflow assembly by saving the management pack.
b) click the … button next to the Script Body property
12) This will bring up this dialog. Paste your script into it:
Here is my script:
Add-PSSnapin smcmdletsnapin ; import-module ActiveDirectory ; Get-ADObject -Filter 'ObjectClass -eq "User"' -SearchBase ' CN=Users,DC=contoso,DC=com ' -Properties CanonicalName, SAMAccountName, WWWHomePage | Select-Object -property @{Name="Domain";Expression={" contoso "}}, SAMAccountName, WWWHomePage | ConvertTo-CSV -NoTypeInformation -OutVariable OutputData ; Clear-Content -Path " C:\Software\CSV\Users.csv " ; $OutputData[1..($OutputData.Count-1)]|ForEach-Object {Add-Content -Value $_ -Path " C:\Software\CSV\Users.csv "};Import-SCSMInstance -DataFileName " C:\Software\CSV\Users.csv " -FormatFileName " C:\Software\CSV\Users.xml "
Note : those items highlighted in the script will need to be changed to match your environment!
Let’s take this apart a bit…
13) Now, click OK on the script body dialog.
14) Right click on the Management Pack in the MP explorer and choose Save.
15) A new .dll file should appear in the same folder as your MP .xml file. Copy this file to the Service Manager folder (%ProgramFiles%\Microsoft System Center\Service Manager 2010) on your Service Manager management server.
16) Until this option is exposed in the authoring console, you’ll need to set the run as account manually in the XML. To do this – open the XML file and find the WriteActionModuleType element. Add an attribute there called RunAs and set the value to a RunAs account. In my case, I used the Operational System Account. That’s the name for it in the console, but in the XML it is DatabaseWriteActionAccount.
<WriteActionModuleType ID="ImportADUserDataRuleWorkflow.PowerShellScript.12a3a306_28ac_4161_97dd_60d0cf9451e0.MT" Accessibility="Public" RunAs="SystemCenter!Microsoft.SystemCenter.DatabaseWriteActionAccount" Batching="false">
If your Operational System Account has the privilege to query the domain, I would suggest using it.
Save these changes to your MP.
17) Import the MP into Service Manager using either the admin console or the Import-SCSMManagementPack PowerShell cmdlet.
18) For purposes of testing this demo out, you can add a Home Page property value in AD to a user by opening the AD Users and Computers snapin, navigating to a user, opening the properties dialog and entering a value in the Web page textbox:
19) Close and reopen your Service Manager console to refresh the cache.
20) Wait until your “connector” runs and then open that user in the Service Manager console and select the Extensions tab to see your extended property and it’s value that was automatically imported in by your custom workflow!
If your workflow doesn’t seem to be working, see this blog post on workflow troubleshooting .
Attached is the demo MP.
-Travis
Follow me on twitter! https://twitter.com/radtravis
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.