Merhaba,
Özellikle büyük ortamlarda bir çok Exchange sunucusu yöneten kişiler için ihtiyaç olacığını düşündüğüm aynı zamanda da kendi ihtiyacımı gidermek için geliştirdiğim, Exchange sunucularını kontrollü bir şekilde restart eden script’i sizinle paylaşmak istedim.
Script, $servers parametresine tanımladığınız Exchange sunucularını sırası gerekli kontrolleri yapıyor ve restart ediyor.
Bu aşamalar şu şekildedir;
#$UserCredential = Get-Credential #$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchangeserver.contoso/PowerShell/ -Authentication Kerberos -Credential $UserCredential #Import-PSSession $Session -DisableNameChecking Add-PSSnapin *exch* $servers = "exchangeserver01.contoso","exchangeserver02.contoso" Function CheckStatus { Param($Server) Try { $testConn = Test-NetConnection -ComputerName $Server -ErrorAction Stop -WarningAction Stop Write-Host -ForegroundColor Green "Checking connection to " $Server ".." If($testConn.PingSucceeded -notlike "True"){ Start-Sleep -Seconds 30 CheckStatus -Server $Server } else { $MailboxDBs = Get-MailboxDatabaseCopyStatus -Server $server -ErrorAction Stop -WarningAction Stop $ComponentStates = Get-ServerComponentState -Identity $server | ? {$_.State -ne "Active"} If($ComponentStates.count -ne 0) { foreach($c in $ComponentStates.Component) { Set-ServerComponentState -Identity $server -Component $c -Requester Maintenance -State Active Write-Host -ForegroundColor Green $Server " Components are set to Active" } } foreach($MailboxDB in $MailboxDBs) { $CopyQueue = $MailboxDB.CopyQueueLength $ReplayQueue = $MailboxDB.ReplayQueueLength $MBStatus = $MailboxDB.Status if(($CopyQueue -gt 5) -or ($ReplayQueue -gt 5) -or ($MBStatus -notmatch "Healthy" -and $MBStatus -notmatch "Mounted")) { Start-Sleep -Seconds 30 Write-Host -ForegroundColor Red $server " is not ready.. It will retry after 30 seconds" CheckStatus -Server $Server #until it letter then 5 Queues }else{return $true} } } }Catch { Start-Sleep -Seconds 30 CheckStatus -Server $Server } } foreach($server in $servers) { Try { $testHealthS1 = CheckStatus -Server $server }Catch { Write-Host -ForegroundColor Red "HealtCheck Process Failed..." } If($testHealthS1 -eq "True") { Try { Move-ActiveMailboxDatabase -Server $server -SkipLagChecks -SkipMoveSuppressionChecks -ErrorAction Stop -WarningAction Stop -Confirm:$false }Catch { Write-Host -ForegroundColor Red "HealtCheck Process Failed..." Break; } $testHealthS2 = CheckStatus -Server $server If($testHealthS2 -eq "True") { Restart-Computer -ComputerName $server Write-Host -ForegroundColor Green $server " is restarting!" Start-Sleep -Seconds 300 }else { Write-Host -ForegroundColor Red "HealtCheck Process Failed..." Break; } $testHealthS3 = CheckStatus -Server $server If($testHealthS3 -eq "True") { Write-Host -ForegroundColor Green $server " is restarted!" }else { Write-Host -ForegroundColor Red "HealtCheck Process Failed..." Break; } } }
Umarım faydalı olmuştur, sorularınızı ayyildizrdm@gmail.com adresine gönderebilirsiniz.
Teşekkürler,