Blog
Archive
<April 2014>
SunMonTueWedThuFriSat
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
Monthly
Go
Search
  |  

Change Service Manager Connector Schedule

Apr 2

Written by:
Monday, April 02, 2012 7:38:55 PM  RssIcon

I’ve now heard from multiple customers that they want to better control when their Service Manager connectors are running. For whatever reason, Microsoft didn’t really include a UI to control the schedule of most connectors, except for the SCCM and SCOM connectors. What if you want to control the schedule for the Active Directory connector, for example?

You have the following options:

Method 1: Initiate the synchronization using PowerShell

SCSM has a rich PowerShell API. The cmd-let Start-SCSMConnector allows you to initiate the synchronization.

On my test machine, I have a connector called “AD, all users”. When I start the Service Manager Shell and execute the command
Get-SCSMConnector
I get a list like this:

image

The command
Get-SCSMConnector | fl
will show some more information, including the schedule (sync time, type and interval):

image

As you can see from the screenshot above, the AD connector will synchronize automatically every day at 2:00 AM

Now to start connectors using PowerShell immediately, you just need to get one or more connectors into a variable and pipe it to the Start-SCSMConnector cmd-let. In my case I just want to start this single connector but you could modify the line to include more connectors in the WHERE-OBJECT:

image

You could write this in one line, of course but for better readability I used a variable.

After you’ve executed the command, you will see the connector will start synchronizing after a minute or so.

Conclusion:
This is an easy way to start the connectors on your own schedule (using the task scheduler) or initiate synchronization at the end of an Orchestrator runbook. For example: consider an Orchestrator runbook which creates a user in the domain, executes a sync on the domain controllers and immediately start the connector for Service Manager afterwards.

Method 2: Change the synchronization schedule using PowerShell

Update: After fixing the last line in the script, the code works as expected. To be clear, MS may not support this, so I recommend you test this in a lab environment before you go ahead and use it.

Loading SDK Assemblies

To change the schedule on the connector itself, a little SDK magic is necessary. To access the SDK from PowerShell we need to load the SDK assembly. Type the following commands (assuming your service manager install directory is the default directory):

[Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft System Center 2012\Service Manager\SDK Binaries\Microsoft.EnterpriseManagement.Core.dll")

image

[Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft System Center 2012\Service Manager\SDK Binaries\Microsoft.EnterpriseManagement.ServiceManager.dll")

image

Connecting to the Management Group

$MG = New-Object Microsoft.EnterpriseManagement.ServiceManagementGroup “localhost”

Since I’m executing the PowerShell on the machine hosting the SDK service, I can connect to “localhost”. The above command has no output.

Get the AD Connector using the SDK

As we did in the example above, let’s store the AD connector we want to change in the variable $ad:

$ad = $MG.ConnectorFramework.GetConnectors() | where {$_.DisplayName -eq 'AD, all users'}

image

Note that the connector object from the SDK looks quite different compared to the one we used in the above PowerShell example.

Get the Enum from the SDK

Now let’s get the Enum with the Name “SyncTypeEnum”:

$EnumSyncType = $MG.EntityTypes.GetEnumerations() | where {$_.Name -eq 'SyncTypeEnum'}

image

The next command will get all child elements for the SyncType enumeration we gathered above:

$SyncTypes = $MG.EntityTypes.GetChildEnumerations($EnumSyncType.Id, [Microsoft.EnterpriseManagement.Common.TraversalDepth]::OneLevel)

image

If you select all the names from the $SyncTypes array, you’ll see the possible values. By default, the AD connector syncs Daily, we want to change that to every 2 hours.

Change the Sync Type and Interval

To change the SyncType and SyncInterval values using the SDK, type:

$ad.ConnectorObject.Item($null, "SyncType").Value = $SyncTypes | where {$_.Name -eq 'SyncTypeEnum.Hours'}
$ad.ConnectorObject.Item($null, "SyncInterval").Value = 2
$ad.ConnectorObject.Commit()
$MG.LinkingFramework.UpdateDataSource($ad.ConnectorObject.Id)

 

The last two lines are used to commit and save the changes to the management group.

image

As you can see, we’ve changed the connector schedule to every two hours.

Conclusion:
Compared to method 1, this is much more complicated, geeky and is prone to error. In the spirit of KISS (keep it simple and stupid) I recommend method 1. Much easier to setup and change.

cheers,
Stefan
http://www.code4ward.net

Tags:
Categories:

2 comment(s) so far...


Gravatar

Re: Change Service Manager Connector Schedule

Thank you Stefan for the above! But still I need a little help. I run into the following, when I created a scheduled task and tell it to sync. every day on 6.00AM this works great. Unfortunately, Service Manager lives his one live, because the connector also synchronizing on 9.00PM (default time I think). But when I exectute Get-SCSMConnector | fl, I see the 2.00AM time. Can you help me out with this one. Thanks in advance.

By Wouter Visser on   Thursday, September 19, 2013 8:51:49 AM
Gravatar

Re: Change Service Manager Connector Schedule

Hmm, not sure why it's synching at 9 PM. Could it be a time zone issue?

By Stefan Koell on   Thursday, September 19, 2013 3:19:47 PM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel