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

[玩转系统] 如何使用 PowerShell 停止和启动所有 SharePoint 2013 服务器场服务?

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

如何使用 PowerShell 停止和启动所有 SharePoint 2013 服务器场服务?


在修补 SharePoint 之前,最佳做法是停止所有 SharePoint 2013 及其相关服务,然后在修补完成后启动。如果您不这样做,您的服务包或补丁安装将花费比预期更长的时间。

那么要停止的服务有哪些?

  • SharePoint 2013 搜索服务(SharePoint 2016 中的 OSearch15 - OSearch16)
  • SharePoint 2013 计时器作业 (SPTimerV4)
  • SharePoint 2013 管理 (SPAdminV4)
  • SharePoint 2013 跟踪 (SPTraceV4)
  • SharePoint 2013 VSS 编写器 (SPWriterV4)
  • SharePoint 2013 用户代码主机 (SPUserCodeV4)
  • SharePoint 搜索主机控制器 (SPSearchHostController)
  • 最前沿同步服务 (FIMSynchronizationService)
  • 前沿服务(FIMService)
  • 万维网发布服务 (W3SVC)
  • 互联网信息服务 (IIS)

[玩转系统] 如何使用 PowerShell 停止和启动所有 SharePoint 2013 服务器场服务?

不要忘记在场的所有 SharePoint 服务器中执行此操作!

停止所有 SharePoint 2013 服务

让我们使用 PowerShell 停止和启动所有 SharePoint 服务:


Add-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$SharePointServices = ('SPSearchHostController','OSearch15','SPWriterV4','SPUserCodeV4','SPTraceV4','SPTimerV4','SPAdminV4','FIMSynchronizationService','FIMService','W3SVC')

#Stop all SharePoint Services
foreach ($Service in $SharePointServices)
{
    Write-Host -ForegroundColor red "Stopping $Service..."
    Stop-Service -Name $Service
}

#Stop IIS
iisreset /stop

启动所有 SharePoint 2013 服务:

修补后,使用以下脚本启动所有 SharePoint 服务。


Add-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$SharePointServices = ('SPSearchHostController','OSearch15','SPWriterV4','SPUserCodeV4','SPTraceV4','SPTimerV4','SPAdminV4','FIMSynchronizationService','FIMService','W3SVC')

#Start all SharePoint Services
foreach ($Service in $SharePointServices)
{
    Write-Host -ForegroundColor green "Starting $Service..."
    Start-Service -Name $Service
}

#Start IIS
iisreset /start

当您想要对 SharePoint SQL 数据库执行一些维护活动并需要停止所有 SharePoint 连接时,您可能需要此脚本!请注意,根据服务器角色,您可能必须停止分布式缓存服务:DCLoadBalancer15、DCLauncher15。

在所有服务器上完全停止或启动 SharePoint 场服务:

让我们将所有内容放在一起并创建一个可重用的 PowerShell 函数,该函数将停止或启动场中所有服务器中的所有 SharePoint 相关服务。


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function StartOrStop-SPFarm()
{
    Param(
    [parameter(Mandatory=$true)] $StartOrStopOption
    )

    #Get All Servers in the Farm 
    $Farm = Get-SPFarm
    $Servers = $Farm.Servers | Where-Object {$_.Role -ne [Microsoft.SharePoint.Administration.SPServerRole]::Invalid} 
    Write-Host "Total Number of Servers in the Farm: " $Servers.Count 

    #List of All SharePoint Services
    $SharePointServices = ('SPSearchHostController','OSearch15','SPWriterV4','SPUserCodeV4','SPTraceV4','SPTimerV4','SPAdminV4','FIMSynchronizationService','FIMService','W3SVC','DCLoadBalancer15', 'DCLauncher15')

    #Iterate through each server
    $Servers | ForEach-Object {
     Write-Host "Performing Operation on Server:" $_.Name
       
        #Loop through each service
     foreach($ServiceName in $SharePointServices)
     {
      $ServiceInstance = Get-Service -ComputerName $_.Name -Name $ServiceName -ErrorAction SilentlyContinue
      if($ServiceInstance -ne $null)
      {
                If($StartOrStopOption -eq "Stop")
                {
                    Try 
                    {
                        Write-Host "Attempting to stop service" $ServiceName ".." -ForegroundColor Yellow
                        Stop-Service -InputObject $ServiceInstance
                        Write-Host "Stopped Service" $ServiceName -ForegroundColor Green 
                    }

                   catch 
                    {
                       Write-Host "Error Occured on Stopping Service. " $_.Message  -ForegroundColor Red 
                    }
                }
                elseif ($StartOrStopOption -eq "Start")
                {
                    Try 
                    {
                        Write-Host "Attempting to start service" $ServiceName ".." -ForegroundColor Yellow
                        Start-Service -InputObject $ServiceInstance
                        Write-Host "Started Service" $ServiceName -ForegroundColor Green 
                    }
                   catch 
                    {
                     Write-Host "Error Occured on Starting Service. " $_.Message  -ForegroundColor Red 
                    }   
                }
           }
     }
        #Start of Stop IIS
        If($StartOrStopOption -eq "Stop") { iisreset /stop} elseif ($StartOrStopOption -eq "Start") {iisreset /start}
    }
}

#Call the function to Stop or Start Services
StartOrStop-SPFarm -StartOrStopOption "Stop"
#StartOrStop-SPFarm -StartOrStopOption "Start"

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

取消回复欢迎 发表评论:

关灯