Skip to content

Instantly share code, notes, and snippets.

@desek
Last active November 9, 2021 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desek/1edf1f404d7ec58531be to your computer and use it in GitHub Desktop.
Save desek/1edf1f404d7ec58531be to your computer and use it in GitHub Desktop.
Rerun all SCSM DW jobs
$smdir = (Get-ItemProperty "HKLM:\Software\Microsoft\System Center\2010\Service Manager\Setup").InstallDirectory
Import-Module "$smdir\Microsoft.EnterpriseManagement.Warehouse.Cmdlets.psd1"
$SleepTimer = 120
$JobTypes = @(
"DWMaintenance",
"MPSyncJob",
"Extract_",
"Transform.",
"Load.",
"Process."
)
$Jobs = Get-SCDWJob
Foreach ($Job in $Jobs)
{
Disable-SCDWJobSchedule -JobName $Job.Name -Verbose
Disable-SCDWJob -JobName $Job.Name -Verbose
Stop-SCDWJob -JobName $Job.Name -Verbose
Start-Sleep -Seconds ($SleepTimer/4)
}
Start-Sleep -Seconds ($SleepTimer*2)
Foreach ($JobType in $JobTypes)
{
Foreach ($Job in ($Jobs | Where-Object {$_.Name -like "$($JobType)*"}))
{
Write-Output "[$(Get-Date -Format HH:mm:ss)] $($Job.Name): Starting"
Enable-SCDWJob -JobName $Job.Name -Verbose
Start-Sleep -Seconds $SleepTimer
Start-SCDWJob -JobName $Job.Name -Verbose
do {
Write-Output "[$(Get-Date -Format HH:mm:ss)] $($Job.Name): Running"
Start-Sleep -Seconds $SleepTimer
} while ((Get-SCDWJob -JobName $Job.Name).Status -eq "Running")
Write-Output "[$(Get-Date -Format HH:mm:ss)] $($Job.Name): Completed"
}
}
$Jobs = Get-SCDWJob
Foreach ($Job in $Jobs)
{
If ($Job.IsEnabled -eq $false)
{
Enable-SCDWJob -JobName $Job.Name -Verbose
}
Enable-SCDWJobSchedule -JobName $Job.Name -Verbose
}
@muradakram
Copy link

How long can this script run? In my environment, It has been running for over 24 hours now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment