-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_patch_script.ps1
executable file
·27 lines (17 loc) · 1.11 KB
/
post_patch_script.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$logfile = "c:\dcsto\scripts\WindowsUpdate.log"
function Get-TimeStamp {
return "{0:yyyy-MM-dd} {0:HH:mm:ss}" -f (Get-Date)
}
### Start of post patch script
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn;
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -auto
$dag = Get-DatabaseAvailabilityGroup
$StopDagServerMaintenance = join-path -path $exscripts -ChildPath StopDagServerMaintenance.ps1
$RedistributeActiveDatabases = join-path -path $exscripts -ChildPath RedistributeActiveDatabases.ps1
invoke-expression -command "$StopDagServerMaintenance -servername $env:computername"
invoke-expression -command "$RedistributeActiveDatabases -dagname $dag.Name -BalanceDbsByActivationPreference -Confirm:$False"
### End of post patch script
schtasks /delete /tn "Post patch script" /F
if ($LASTEXITCODE -eq 0) {Write-Output "$(Get-TimeStamp) INFO Post patch script successful, deleting task" | Out-file -FilePath $logfile -Append}
Else {Write-Output "$(Get-TimeStamp) WARNING Post patch script failed with exitcode ${$LASTEXITCODE}, deleting task" | Out-file -FilePath $logfile -Append}