There is a web service interface and .NET assemblies which can be used to make changes to the jobs running in the TFS Background Agent. I found it easier to use PowerShell to load the .NET assemblies and work with the object model. Note that my assembly versions are 11.0.0.0 because I ran this using TFS 2013. The assembly versions are different in other TFS versions.
Prior to the AD account migration you should disable the AD sync job. On the TFS Application Tier server the Powershell code needed to disable the AD sync job is...
[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Client, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$TFSConfigurationServer = New-Object Microsoft.TeamFoundation.Client.TfsConfigurationServer(New-Object System.Uri("http://YourTFSServer:8080/tfs"))
$TFSJobService = $TFSConfigurationServer.GetService([Microsoft.TeamFoundation.Framework.Client.ITeamFoundationJobService])
<#
Team Foundation Server Periodic Identity Synchronization
544dd581-f72a-45a9-8de0-8cd3a5f29dfe
#>
foreach($Job in $TFSJobService.QueryJobs())
{
if($Job.JobId -eq "544dd581-f72a-45a9-8de0-8cd3a5f29dfe") { break }
}
$CurrentJobState = $Job.EnabledState
$NewState = [Microsoft.TeamFoundation.Framework.Common.TeamFoundationJobEnabledState]::FullyDisabled
$Job.EnabledState = $NewState
$TFSJobService.UpdateJob($Job)
After the user account migration you can run TFSConfig Identities to make the necessary updates within TFS. Then run more PowerShell to turn the AD Sync job back on...
[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Client, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Common, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$TFSConfigurationServer = New-Object Microsoft.TeamFoundation.Client.TfsConfigurationServer(New-Object System.Uri("http://YourTFSServer:8080/tfs"))
$TFSJobService = $TFSConfigurationServer.GetService([Microsoft.TeamFoundation.Framework.Client.ITeamFoundationJobService])
<#
Team Foundation Server Periodic Identity Synchronization
544dd581-f72a-45a9-8de0-8cd3a5f29dfe
#>
foreach($Job in $TFSJobService.QueryJobs())
{
if($Job.JobId -eq "544dd581-f72a-45a9-8de0-8cd3a5f29dfe") { break }
}
$CurrentJobState = $Job.EnabledState
$NewState = [Microsoft.TeamFoundation.Framework.Common.TeamFoundationJobEnabledState]::Enabled
$Job.EnabledState = $NewState
$TFSJobService.UpdateJob($Job)
One other useful item is that you can view the status of the most recent run of the AD sync job using the QueryLatestJobHistory method.
$TFSJobService.QueryLatestJobHistory("544dd581-f72a-45a9-8de0-8cd3a5f29dfe")
Note that it won't run again until the top of the hour after it's been re-enabled.