Here's what I'm trying to run: $SPServer=Get-SPServer | Where {($.Role -isnotlike 'Invalid') and ($
$SPServer=Get-SPServer | Where {($_.Role -isnotlike 'Invalid') and ($_.Status -is 'Online')}
Edit: Here's the correct string.Status -is 'Online')} Thank you Zack.
$SPServers = Get-SPServer | Where-Object { $_.Role -notlike ‘Invalid’ } | Select-Object -ExpandProperty Address
Edit: updated the script with the select string from Zack, as well as some changes to the folder filters to not select the Central Admin folder.
$SPServerWrite-Host =" Get-Content "C:\Tools\QTCServers.txt"
ForEachYou ($Serverare inhere $List)
{because
$Service=(Get-Serviceyou -ComputerNameneed $Server.ComputerNameto -Namereset $Server.Service)
Stop-Servicethe -InputObjectConfig $ServiceCache -Verbose
$Servicein your SharePoint Farm.WaitForStatus('Stopped','00:00:15')
}
ForEach ($Server in $List)
{
Get-Service -InputObject $Service -Verbose
}
Start-Sleep -Seconds 2
There are 4 options to choose from.
You can run a test to make sure the settings in the script are correct and will
actually do what they're supposed to do and not delete your whole farm.....
(I highly suggest you do this first)
You can actually do a Reset, and delete the .xml files that are in the config folders.
If you forgot something, or something came up, you can Start the timer services back up
without having to completely exit.
Or you can always choose to Stop if you are too chicken to pull the trigger.
" -ForegroundColor White -BackgroundColor Red
$SPServers = Get-SPServer | Where-Object { $_.Role -notlike ‘Invalid’ } | Select-Object -ExpandProperty Address
do{write-host "Type TEST to " -foregroundcolor Black -backgroundcolor White -nonewline; Write-Host "--TEST--" -foregroundcolor Black -backgroundcolor Green -nonewline; Write-Host "resetting the config cache on all the servers in the farm" -foregroundcolor black -backgroundcolor white
write-host "Type RESET to " -foregroundcolor Red -backgroundcolor White -NoNewline; Write-Host "!! RESET !!" -ForegroundColor BlackWhite -BackgroundColor Red -NoNewline; Write-Host "the config cache on all the servers in the farm" -foregroundcolor red -backgroundcolor white
write-host "Type START to start the SharePoint Timer Service on all the servers in the farm" -foregroundcolor black -backgroundcolor white
write-host "Type STOP if you need to go call your mom." -foregroundcolor whiteBlack -backgroundcolor yellowWhite
$selection = read-host
if ($selection -eq 'TEST')
{
Write-Host "TESTING!!!! Clearing the Config Cache on Farm Servers" -ForegroundColor White -BackgroundColor Green
Start-Sleep -Seconds 4
ForEach ($Server$SPServer in $SPServer$SPServers)
{
if ( -Not (Test-Path \\$Server\c$\ProgramData\Microsoft\SharePoint\Config\\$SPServer\c$\ProgramData\Microsoft\SharePoint\Config))
{
Write-Host "Cannot find folder for "\\$Server\c$\Tools\ClearConfigCache"\\$SPServer\c$\Tools\ClearConfigCache
}
else {
Get-ChildItem -Path \\$Server\c$\ProgramData\Microsoft\SharePoint\Config\*\\$SPServer\c$\ProgramData\Microsoft\SharePoint\Config\*.* -Recurse | RemoveWhere-ItemObject {($_.Name -Includene 'cache.ini') -and ($_.FullName -notlike '*00000000-0000-0000-0000-000000000000*') -and ($_.Name -like '*.xml')} -Exclude| '*cache*'Remove-Item -Force -Verbose -WhatIf
Get-ChildItem -Path \\$Server\c$\ProgramData\Microsoft\SharePoint\Config\*\\$SPServer\c$\ProgramData\Microsoft\SharePoint\Config\*.* -Recurse | Where-Object {($_.Name -eq 'cache.ini'}) |-and Clear($_.FullName -Contentnotlike '*00000000-Include0000-0000-0000-000000000000*')} 'cache.ini'| Clear-Exclude '*.xml'Content -Force -WhatIf
Get-ChildItem -Path \\$Server\c$\ProgramData\Microsoft\SharePoint\Config\*\\$SPServer\c$\ProgramData\Microsoft\SharePoint\Config\*.* -Recurse | Where-Object {($_.Name -eq 'cache.ini') -and ($_.FullName -notlike '*00000000-0000-0000-0000-000000000000*')} | Add-Content -Value "1" -Verbose -WhatIf
Write-Host "Cache clear and reset complete on" $Server$SPServer -ForegroundColor White -BackgroundColor Green
}
{
Start-Sleep -Seconds 2
}
}
}
elseif ($selection -eq 'RESET')
{
Write-Host "Clearing the Config Cache on Farm Servers" -ForegroundColor Red -BackgroundColor Black
ForEach ($Server in $SPServer$SPServers)
{
$Service=(Get-Service -ComputerName $Server -Name 'SPTimerV4')
Stop-Service -InputObject $Service -Verbose
$Service.WaitForStatus('Stopped','00:00:15')
}
ForEach ($Server in $SPServers)
{
Get-Service -InputObject $Service -Verbose | Format-Table MachineName,Status,Name,DisplayName
}
Write-Host "You have about 10 seconds if you want to abort this operation. Press Ctrl+C to stop"
Start-Sleep -Seconds 10
ForEach ($Server in $SPServers)
{
if ( -Not (Test-Path \\$Server\c$\ProgramData\Microsoft\SharePoint\Config))
{
Write-Host "Cannot find folder for "\\$Server\c$\ProgramData\Microsoft\SharePoint\Config
}
else {
Get-ChildItem -Path \\$Server\c$\ProgramData\Microsoft\SharePoint\Config\*.* -Recurse | Select Name, FullName | Where-Object {($_.Name -ne 'cache.ini') -and ($_.FullName -notlike '*00000000-0000-0000-0000-000000000000*') -and ($_.Name -like '*.xml')} | Remove-Item -Include '*.xml' -Exclude '*cache*' -Force -Verbose
Get-ChildItem -Path \\$Server\c$\ProgramData\Microsoft\SharePoint\Config\*.* -Recurse | Select Name, FullName | Where-Object {($_.Name -eq 'cache.ini'}) |-and Clear($_.FullName -Contentnotlike '*00000000-Include0000-0000-0000-000000000000*')} 'cache.ini'| Clear-Exclude '*.xml'Content -Force
Get-ChildItem -Path \\$Server\c$\ProgramData\Microsoft\SharePoint\Config\*.* -Recurse | Select Name, FullName | Where-Object {($_.Name -eq 'cache.ini') -and ($_.FullName -notlike '*00000000-0000-0000-0000-000000000000*')} | Add-Content -Value "1" -Verbose
Write-Host "Cache clear and reset complete on" $Server -ForegroundColor White -BackgroundColor Green
}
{
Start-Sleep -Seconds 2
}
}
}
elseif ($selection -eq 'START')
{
ForEach ($Server in $List$SPServers)
{
$Service=(Get-Service -ComputerName $Server.ComputerName -Name $Server.Service'SPTimerV4')
Start-Service -InputObject $Service -Verbose
$Service.WaitForStatus('Running','00:00:15')
}
ForEach ($Server in $SPServers)
{
Get-Service -InputObject $Service -Verbose | Format-Table MachineName,Status,Name,DisplayName
}
}
elseif ($selection -eq 'STOP')
{
ForEach ($Server in $List$SPServers)
{
$Service=(Get-Service -ComputerName $Server.ComputerName -Name $Server.Service'SPTimerV4')
Start-Service $Service -Verbose
$Service.WaitForStatus('Running','00:00:15')
}
ForEach ($Server in $SPServers)
{
Get-Service -InputObject $Service -Verbose | Format-Table MachineName,Status,Name,DisplayName
}
Write-Host "Fine! Be that way!" -ForegroundColor Black -BackgroundColor White
Start-Sleep -Seconds 5
exit
}
else
{
"Really? You only had 4 choices! How hard was that? You probably need to rethink your life."
Start-Sleep -Seconds 5
"Fine....Let's try this again, shall we?"
Start-Sleep -Seconds 3
}
}
Until ($selection -eq 'STOP','RESET')
ForEach ($Server in $List$SPServers)
{
$Service=(Get-Service -ComputerName $Server.ComputerName -Name $Server.Service'SPTimerV4')
Start-Service -InputObject $Service -Verbose
$Service.WaitForStatus('Running','00:00:15')
}
ForEach ($Server in $List$SPServers)
{
Get-Service -InputObject $Service -Verbose
}
$SPFarmServers.Dispose()
$SPServers.Dispose()
$Server.Dispose()
Write-Host "Thank you for playing, hope it all works out for you!" -foregroundcolor DarkCyan -backgroundcolor Magenta