Unfortunately, AD connect doesn’t have a ability to change it schedule. For SCSM 2010 AD connector runs one per hour, for SCSM 2012 it run once per 24 hours. For small domain this is acceptable schedule but for large domains with many users it can be potential risk of overload of the SQL or SCSM servers. AD connector get from AD only objects changes since last run but even this amount of data can be large and reduce workload to SCSM management server and even more to SQL server.
When AD connector sync data from AD it’s save the domain’s “update sequence number” (USN). When connector run next time it get only object that have uSNChanged property more then last saved USN. Unfortunately connector can’t detect which field of the object are changed and get all object with a larger uSNChanged and saved it to temp table in the ServiceManager database.
To reduce the negative impact you can use two different ways: separate one connect to several small (by OU ot by object’s type or by LDAP query in case of SCSM12), or you can change the connector’s schedule. But you can’t use second approach with AD connector because UI and even cmdlets have no ability to do that (with UI or cmdlets you can enable or disable AD connector only). But you can use SDK to do that, and you can use PowerShell to use SDK.
Some piece of theory before we start powershelling. Connector to AD or SCCM can run with one of the next intervals:
Interval |
Description |
Configurable parameters |
SyncType Value |
Minute | Run each N minutes | Minutes count between runs | SyncTypeEnum.Minutes |
Hour | Run each N hours | Hours count between runs | SyncTypeEnum.Hours |
Day | Run each N days | Days count between runs Time of the run |
SyncTypeEnum.Daily |
Week | Run once per week | Day of week Time of the run |
SyncTypeEnum.Weekly |
Month | Run once per month | Day of month Time of the run |
SyncTypeEnum.Monthly |
Once | Run one time | Date and time | SyncTypeEnum.None |
Configuration data for each connector are stored on objects of the “System.LinkingFramework.DataSource” class. That class has many properties but in this time we must use next:
Property |
Description |
SyncType | Type of the interval, see table above |
SyncInterval | Set the interval count (minutes, hours or dates) or day of the week or day of the month |
SyncTime | Execution time (DateTime type). Not significant part of the DateTime value are ignored. As example, for “hours” the connector get only minutes and seconds and ignored all over parts. |
Unfortunately we can’t get and changed connector object’s property as usual object in SCSM. To do that we must use special methods and special approach.
Get connector’s schedule
Let’s start by reading the schedule. If you already working with SDK and PowerShell note to class used to connect to SCSM. You must use ServiceManagementGroup instead of EnterpriseManagementGroup. See the script below:
# store the path to SCSM folder. $SMDIR = (Get-ItemProperty "hklm:\SOFTWARE\Microsoft\System Center\2010\Service Manager\Setup\").InstallDirectory # Path to SDK assemblies $SMSDKDIR = "${SMDIR}\SDK Binaries" # Path to main SDK DLL... $SMDLL = "${SMSDKDIR}\Microsoft.EnterpriseManagement.Core.dll" # .. and additional DLL $SMADDDLL = "${SMSDKDIR}\Microsoft.EnterpriseManagement.ServiceManager.dll" # Load both assemblies [reflection.assembly]::LoadFile($SMDLL) | out-null [reflection.assembly]::LoadFile($SMADDDLL) | out-null # Connect to SCSM server $ServiceManagementGroup = new-object Microsoft.EnterpriseManagement.ServiceManagementGroup "localhost" # Get all connectors $connectors = $ServiceManagementGroup.ConnectorFramework.GetConnectors() foreach($connector in $connectors) { # get nessesary properties of the connector write-host $connector.DisplayName write-host ("`tSyncType: " + $connector.ConnectorObject.Item($null,"SyncType").Value) write-host ("`tSyncInterval: " + $connector.ConnectorObject.Item($null,"SyncInterval").Value) if($connector.ConnectorObject.Item($null,"SyncTime").Value) { $syncTime = $connector.ConnectorObject.Item($null,"SyncTime").Value.ToLocalTime() } else {$syncTime = $null} write-host ("`tSyncTime: " + $syncTime) write-host "----------------" }
Example of the output for my test environment:
Alerts From OpsMgr SyncType: SyncInterval: SyncTime: ---------------- CI from SCOM SyncType: SyncInterval: SyncTime: ---------------- Connector to SCCM SyncType: SyncTypeEnum.Weekly SyncInterval: 2 SyncTime: 02/29/2012 02:00:00 ---------------- LinkingFramework Server SyncType: SyncInterval: SyncTime: ---------------- SDKDefaultConnector SyncType: SyncInterval: SyncTime: ---------------- Connector to local AD SyncType: SyncTypeEnum.Hours SyncInterval: 1 SyncTime: 07/26/2010 22:43:48 ----------------
Note to two connectors: “SDKDefaultConnector” и “LinkingFramework Server”. This is intervals SCSM’ connectors and you must do not change it properties. Connectors “Alerts From OpsMgr” and “CI from SCOM” related to OpsMgr.
Connector to SCCM configured to run each week (SyncTypeEnum.Weekly) at Tuesday (SyncInterval = 2) at 02:00 (SCSM store all DataTime values as UTC, my current time zone is UTC+4, 22:00 + 4 hour = 02:00). In this case date, month and year part are ignored.
Connector to AD configured to run each hour at 43 minute (almost at 44). In this case hour, date, month and year part of the value are ignored.
Change connector’s schedule
To change the connector’s schedule we must set properties then save connector’s settings object and then update connector’s object itself.
$SMDIR = (Get-ItemProperty "hklm:\SOFTWARE\Microsoft\System Center\2010\Service Manager\Setup\").InstallDirectory $SMSDKDIR = "${SMDIR}\SDK Binaries" $SMDLL = "${SMSDKDIR}\Microsoft.EnterpriseManagement.Core.dll" $SMADDDLL = "${SMSDKDIR}\Microsoft.EnterpriseManagement.ServiceManager.dll" [reflection.assembly]::LoadFile($SMDLL) | out-null [reflection.assembly]::LoadFile($SMADDDLL) | out-null $ServiceManagementGroup = new-object Microsoft.EnterpriseManagement.ServiceManagementGroup "localhost" # Get all SyncTypeEnum enums $syncTypeEnum = $ServiceManagementGroup.EntityTypes.GetEnumerations() | ? {$_.Name -eq "SyncTypeEnum"} $allSyncTypesEnums = $ServiceManagementGroup.EntityTypes.GetChildEnumerations($syncTypeEnum.Id, [Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive) # Get connector by DisplayName (as displayed in SCSM console) $connectors = $ServiceManagementGroup.ConnectorFramework.GetConnectors() | ? {$_.DisplayName -eq "AD Main"} foreach($connector in $connectors) { write-host $connector.DisplayName $connector.ConnectorObject.Item($null,"SyncType").Value = $allSyncTypesEnums | ? {$_.Name -eq "SyncTypeEnum.Daily"} $connector.ConnectorObject.Item($null,"SyncInterval").Value = 1 $connector.ConnectorObject.Item($null,"SyncTime").Value = ([datetime]"03.03.2012 19:00").ToUniversalTime() write-host "`tUpdating...." $connector.ConnectorObject.Commit() $ServiceManagementGroup.LinkingFramework.UpdateDataSource($connector.ConnectorObject.Id) write-host "`tComplete" write-host "" }
This script for connector “AD Main” set schedule to run each day at 19:00 (local time). Note to saving changes: it’s completed with two steps as described above.
All scripts working for both, SCSM 2010 and SCSM 2012, versions.
5 Comments
Hi, good post, but a question on the weekly interval. Up above you say that the weekly interval is “Weeks count between runs”. So a 1 would mean every week, a 2 would be every 2 weeks, etc…
However, down below you say this:
Connector to SCCM configured to run each week (SyncTypeEnum.Weekly) at Tuesday (SyncInterval = 2) at 02:00
I don’t understand that line. You say it’s configured to run each week, but the SyncInterval=2, implying it will run every 2 weeks?
Can you clarify that please?
Thanks
Sorry, my mistake. Fixed.
[…] bit complex by using SMLets. But this is shouldn’t be a problem for you if you remember my old article about changing AD Connector scheduler. I will publish both […]
[…] of an ugly hack, but it seems to work well. there are better ways to read data from connectors, but they mostly require assembly reflection and knowledge of the SDK, so I made a judgement […]
[…] A great blog reference here: http://blog.scsmsolutions.com/2012/03/update-ad-and-sccm-connector-scheduler-with-powershell […]