当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 在 SharePoint 中使用 PowerShell 启用-禁用计时器作业

作者:精品下载站 日期:2024-12-14 14:12:44 浏览:16 分类:玩电脑

在 SharePoint 中使用 PowerShell 启用-禁用计时器作业


计时器作业通过 Windows 计时器服务在 SharePoint 中执行特定任务,例如在计划时间发送电子邮件警报。在 SharePoint 管理中心网站中,您可以检查计时器作业、禁用或启用特定计时器作业。

用于检查计时器作业状态的 PowerShell 脚本:


#Function to Check Timer job status
Function Get-TimerJobStatus($TimerJobName)
{
    $TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName } 
    if($TimerJob -eq $null)
    {
        Write-host "Timer job not found!" -ForegroundColor Red
        return
    }
    $TimerJobDisabled = $TimerJob | Select -ExpandProperty IsDisabled
    if($TimerJobDisabled)
    {
        Write-host "Timer Job is Disabled!"  -ForegroundColor Yellow
    }
    else
    {
        Write-host "Timer Job is Enabled!"  -ForegroundColor Green
    }
    
}

$TimerJobName="My Site Cleanup Job"
Get-TimerJobStatus $TimerJobName

如何在 SharePoint 中禁用计时器作业?

要禁用计时器作业,请转到管理中心>>监控>>计时器作业>>查看作业定义>>从SharePoint 2013中的计时器作业列表中选择您的目标>>单击“禁用”按钮以禁用计时器工作。

[玩转系统] 在 SharePoint 中使用 PowerShell 启用-禁用计时器作业

使用 PowerShell 禁用 SharePoint 计时器作业

以下是在 SharePoint 中禁用计时器作业的 PowerShell:


#Function to Disable a Timer job
Function Disable-TimerJob($TimerJobName)
{
    $TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName } 
    if($TimerJob -eq $null)
    {
        Write-host "Timer job not found!" -ForegroundColor Red
        return
    }
    $TimerJobDisabled = $TimerJob | Select -ExpandProperty IsDisabled
    if($TimerJobDisabled)
    {
        Write-host "Timer Job is already Disabled!" -ForegroundColor Yellow
    }
    else
    {
        $TimerJob | Disable-SPTimerJob 
        Write-host "Timer Job Disabled!" -ForegroundColor Green
    }
    
}

#Timer job name to disable
$TimerJobName="My Site Cleanup Job"

#Call the function to Disable Timer job
Disable-TimerJob $TimerJobName

在 SharePoint 中激活计时器作业:

要激活禁用的计时器作业,请转至:

  • 中央管理 >> 监控 >> 计时器作业
  • 查看作业定义 >> 从 SharePoint 2013 中的计时器作业列表中选择您的目标
  • 单击“启用”按钮以激活计时器作业。

[玩转系统] 在 SharePoint 中使用 PowerShell 启用-禁用计时器作业

这将启用 SharePoint 2013 中禁用的计时器作业。

使用 PowerShell 启用 SharePoint 计时器作业:


#Function to Enable a Timer job
Function Enable-TimerJob($TimerJobName)
{
    $TimerJob = Get-SPTimerJob | Where-Object { $_.displayname -like $TimerJobName } 
    if($TimerJob -eq $null)
    {
        Write-host "Timer job not found!" -ForegroundColor Red
        return
    }
    $TimerJobDisabled = $TimerJob | Select -ExpandProperty IsDisabled
    if($TimerJobDisabled)
    {
        $TimerJob | Enable-SPTimerJob 
        Write-host "Timer Job Enabled!" -ForegroundColor Green
    }
    else
    {
        Write-host "Timer Job is Already Enabled!" -ForegroundColor Yellow
    }    
}

#Timer job name to Enable
$TimerJobName="My Site Cleanup Job"

#Call the function to Enable Timer job
Enable-TimerJob $TimerJobName 

这将使用 PowerShell 激活 SharePoint 2010 中的计时器作业。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯