param(
[string] $instancename=‘LAPTOP-CF8KHTV1’,
[string] $sqljoblist = ‘D:\Dell\Biztalk\BizTalkLive\BizTalkPowerShellService\StarStopBTSQLJobs\BTSqlJobs.txt’,
[string] $logpath = ‘D:\Dell\Biztalk\BizTalkLive\BizTalkPowerShellService\StarStopBTSQLJobs\BTSQLJobsActivityLogs.txt’,
[string] $successjoblist = “”,
[string] $failedjoblist = “”,
[string] $writelog = “”
)
Start-Transcript -path $logpath -Append
[System.Reflection.Assembly]::LoadwithPartialName(‘Microsoft.SqlServer.SMO’) | out-null
$serverinstance = New-Object Microsoft.SqlServer.Management.SMO.Server(“$instancename“)
$sqljobs = New-Object System.IO.StreamReader($sqljoblist)
while (($sqljob = $sqljobs.ReadLine()) -ne $null)
{
try{
#To enable BizTalk SQL Job
$job = $serverinstance.jobserver.jobs[“$sqljob“]
if($job.IsEnabled -ne “TRUE”){
$job.IsEnabled = $true
$job.Alter()
$successjoblist = $successjoblist+$sqljob+“`r`n”
}
}
catch{
$failedjoblist = $failedjoblist + ‘SQL Job- ‘+$sqljob+ ‘ caught exception:’+ $_ + ‘ at datetime: ‘+(Get-Date).ToString()+“`r`n”
}
}#End while
if(($sqljobs.EndOfStream) -eq $true){
$sqljobs.Dispose()
}
if($successjoblist.Length -gt 0){
$writelog=‘———————Success———————‘+“`r`n”+$successjoblist+‘———————Success———————‘
Write-Host $writelog
$writelog =“”
}
if($failedjoblist.Length -gt 0){
$writelog=‘———————Error———————‘+“`r`n”+$failedjoblist+‘———————Error———————‘
Write-Host $writelog
$writelog =“”
}
if(($failedjoblist.Length -lt 1) -AND ($successjoblist.Length -lt 1)){
$writelog=‘———————No-Run———————‘+“`r`n”+‘SQL Job(s) are already enabled !’+“`r`n”+‘———————No-Run———————‘
Write-Host $writelog
$writelog =“”
}
Stop-Transcript
param(
[string] $instancename=‘LAPTOP-CF8KHTV1’,
[string] $sqljoblist = ‘D:\Dell\Biztalk\BizTalkLive\BizTalkPowerShellService\StarStopBTSQLJobs\BTSqlJobs.txt’,
[string] $logpath = ‘D:\Dell\Biztalk\BizTalkLive\BizTalkPowerShellService\StarStopBTSQLJobs\BTSQLJobsActivityLogs.txt’,
[string] $successjoblist = “”,
[string] $failedjoblist = “”,
[string] $writelog = “”
)
Start-Transcript -path $logpath -Append
[System.Reflection.Assembly]::LoadwithPartialName(‘Microsoft.SqlServer.SMO’) | out-null
$serverinstance = New-Object Microsoft.SqlServer.Management.SMO.Server(“$instancename“)
$sqljobs = New-Object System.IO.StreamReader($sqljoblist)
while (($sqljob = $sqljobs.ReadLine()) -ne $null)
{
try{
#To enable BizTalk SQL Job
$job = $serverinstance.jobserver.jobs[“$sqljob“]
if($job.IsEnabled -eq “TRUE”){
$job.IsEnabled = $false
$job.Alter()
$successjoblist = $successjoblist+$sqljob+“`r`n”
}
}
catch{
$failedjoblist = $failedjoblist + ‘SQL Job- ‘+$sqljob+ ‘ caught exception:’+ $_ + ‘ at datetime: ‘+(Get-Date).ToString()+“`r`n”
}
}#End while
if(($sqljobs.EndOfStream) -eq $true){
$sqljobs.Dispose()
}
if($successjoblist.Length -gt 0){
$writelog=‘———————Success———————‘+“`r`n”+$successjoblist+‘———————Success———————‘
Write-Host $writelog
$writelog =“”
}
if($failedjoblist.Length -gt 0){
$writelog=‘———————Error———————‘+“`r`n”+$failedjoblist+‘———————Error———————‘
Write-Host $writelog
$writelog =“”
}
if(($failedjoblist.Length -lt 1) -AND ($successjoblist.Length -lt 1)){
$writelog=‘———————No-Run———————‘+“`r`n”+‘SQL Job(s) are already disab !’+“`r`n”+‘———————No-Run———————‘
Write-Host $writelog
$writelog =“”
}
Stop-Transcript
Backup BizTalk Server (BizTalkMgmtDb)
CleanupBTFExpiredEntriesJob_BizTalkMgmtDb
MessageBox_DeadProcesses_Cleanup_BizTalkMsgBoxDb
MessageBox_Message_ManageRefcountLog_BizTalkMsgBoxDb
MessageBox_Parts_Cleanup_BizTalkMsgBoxDb
MessageBox_Updatestats_BizTalkMsgBoxDb
Monitor BizTalk Server (BizTalkMgmtDb)
Operations_OperateonInstances_OnMaster_BizTalkMsgBoxDb
PurgeSubscriptionsJob_BizTalkMsgBoxDb
Rules_Database_Cleanup_BizTalkRuleEngineDb
TrackedMessages_Copy_BizTalkMsgBoxDb
DTA Purge and Archive (BizTalkDTADb)
@ECHO OFF
PowerShell.exe -ExecutionPolicy Bypass D:\Dell\Biztalk\BizTalkLive\BizTalkPowerShellService\StarStopBTSQLJobs\psEnableBTSQLJobs.ps1
ECHO Press any key to exit..
PAUSE >NUL
CLS
EXIT /B
@ECHO OFF
PowerShell.exe -ExecutionPolicy Bypass D:\Dell\Biztalk\BizTalkLive\BizTalkPowerShellService\StarStopBTSQLJobs\psDisableBTSQLJobs.ps1
ECHO Press any key to exit..
PAUSE >NUL
CLS
EXIT /B