Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Powershell Script to Stop SharePoint Timer Service in all Servers in the Farm
WhatsApp
Karthik Muthu Karuppan
Feb 16
2015
5.5
k
0
0
StopTimerService.zip
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
$LogFile =
".\StopTimerServicePatch-$LogTime.rtf"
# Add SharePoint PowerShell Snapin
if
( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $
null
) {
Add-PSSnapin Microsoft.SharePoint.Powershell
}
$scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
Set-Location $scriptBase
#Deleting any .rtf files in the scriptbase location
$FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
if
($FindRTFFile)
{
foreach($file
in
$FindRTFFile)
{
remove-item $file
}
}
start-transcript $logfile
$global:timerServiceName =
"SharePoint 2010 Timer"
$global:timerServiceInstanceName =
"Microsoft SharePoint Foundation Timer"
# Get the local farm instance
[Microsoft.SharePoint.Administration.SPFarm]$farm = [Microsoft.SharePoint.Administration.SPFarm]::get_Local()
Function StopSPTimerServicesInFarm([Microsoft.SharePoint.Administration.SPFarm]$farm)
{
Write-Host
""
foreach($server
in
$farm.Servers)
{
foreach($instance
in
$server.ServiceInstances)
{
# If the server has the timer service then stop the service
if
($instance.TypeName -eq $timerServiceInstanceName)
{
[string]$serverName = $server.Name
Write-Host
"Stop "
$timerServiceName
" service on server: "
$serverName -fore yellow
$service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter
"DisplayName='$timerServiceName'"
$serviceInternalName = $service.Name
sc.exe \\$serverName stop $serviceInternalName > $
null
# Wait until this service has actually stopped
write-host
"Waiting for '$timerServiceName' service on server: "
$serverName
" to be stopped"
-fore yellow
do
{
Start-Sleep 1
Write-Host -foregroundcolor DarkGray -NoNewLine
"."
$service = Get-WmiObject -ComputerName $serverName Win32_Service -Filter
"DisplayName='$timerServiceName'"
}
while
($service.State -ne
"Stopped"
)
write-host
" '$timerServiceName' service on server: "
$serverName
" stopped successfully"
-fore green
break
;
}
}
}
Write-Host
""
}
StopSPTimerServicesInFarm $farm
Stop-transcript
SharePoint
Timer Service
Up Next
Powershell Script to Stop SharePoint Timer Service in all Servers in the Farm