您如何编写Powershell脚本来检查所有服务都在内部前提下在SharePoint 2013和2016上运行? [英] How do you write a powershell script to check all services are running on SharePoint 2013 and 2016 on premise?

查看:59
本文介绍了您如何编写Powershell脚本来检查所有服务都在内部前提下在SharePoint 2013和2016上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想到的脚本,请编辑服务器名称,并在脚本末尾为服务器场中的每个服务器复制条目.

Here's the script I came up with, please edit the server names and duplicate the entry at the end of the script for each server in your server farm.

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'} 
if ($snapin -eq $null) 
{    
    write-output "Loading SharePoint Powershell Snapin"    
    Add-PSSnapin "Microsoft.SharePoint.Powershell"  -EA SilentlyContinue
}
#Script to Check if SharePoint Services are running.
#referencing https://sharepointbjorn.com/2014/10/06/start-and-stop-sharepoint-service-instances-using-powershell/
$ErrorActionPreference = "stop"
$sandbox = Get-WmiObject win32_service | Where-Object {$_.name -eq "SPuserCodeV4"}
$timer =  Get-WmiObject win32_service | Where-Object {$_.name -eq "SPTimerV4"}
$Trace = Get-WmiObject win32_service | Where-Object {$_.name -eq "SpTraceV4"}
if ($sandbox.State -eq "Stopped" -or $timer.State -eq "Stopped" -or $Trace.State -eq "Stopped" )
{
throw "A SharePoint Service is not running" 
}
else
{
Write-Host -ForegroundColor GREEN "All services  running"
Write-Host -ForegroundColor White $sandbox.name "is running with" $sandbox.StartName 
Write-Host -ForegroundColor White $timer.name "is running with" $timer.StartName 
Write-Host -ForegroundColor White $Trace.name "is running with" $Trace.StartName 
}

Function CheckServiceInstance ($Server,$Services)
{
        #Traverse services arrray
        write-host -f Yellow "$Server status: "
        Foreach ($ServiceTypeName in $Services)
        {
            $Service = Get-SPServiceInstance -Server $Server | ? {$_.TypeName -eq $ServiceTypeName}
            #If service is Online, stop it.
            if($Service.status -eq "Online") 
            {
                Write-Host -f Green "$ServiceTypeName is Online on $Server."
            }
            elseif($Service.status -eq "Disabled")
            {
                Write-Host -f Cyan "$ServiceTypeName is Disabled on $Server."            
            }
            else
            {
                Write-Host -f Red "$ServiceTypeName is Not Installed on $Server."            
            }
        }#EndForeach service      
        write-host "-------------------------------------------"
} #EndFunction
#etc change this to your internal server FQDNs in your farm
CheckServiceInstance -Server "servername1" -Services ("Access Services", "App Management Service", "Business Data Connectivity Service", "SQL Server PowerPivot System Service", "Machine Translation Service", "Managed Metadata Web Service", "PerformancePoint Service", "Project Server Application Service", "SharePoint Server Search", "Secure Store Service", "SQL Server Reporting Services Service", "User Profile Service", "Visio Graphics Service", "Word Automation Services")
CheckServiceInstance -Server "servername2" -Services ("Access Services", "App Management Service", "Business Data Connectivity Service", "SQL Server PowerPivot System Service", "Machine Translation Service", "Managed Metadata Web Service", "PerformancePoint Service", "Project Server Application Service", "SharePoint Server Search", "Secure Store Service", "SQL Server Reporting Services Service", "User Profile Service", "Visio Graphics Service", "Word Automation Services")
# missing: "Application Discovery and Load Balancer Service", "Security Token Service Application", "Usage and Health Data Collection Service"
#Get-SPServiceInstance | select typename |  Sort-Object typename | Get-Unique -OnType | % {$_.TypeName}

在构建服务器场后运行此程序,以验证所有服务均按预期运行.

Run this after building your farm to verify all services are running as expected.

在每次部署后运行此命令,并验证一切正常!

Run this after each deployment and verify your all good!

Jaymeson Beck SharePoint开发人员UCOP

Jaymeson Beck SharePoint Developer UCOP

推荐答案

您有什么问题?

What is your question?


这篇关于您如何编写Powershell脚本来检查所有服务都在内部前提下在SharePoint 2013和2016上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆