Last active
November 9, 2021 16:09
-
-
Save desek/1edf1f404d7ec58531be to your computer and use it in GitHub Desktop.
Rerun all SCSM DW jobs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How long can this script run? In my environment, It has been running for over 24 hours now.