forked from bezibaerchen/prtgscripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseCopyActivationPrefCheck.ps1
76 lines (56 loc) · 1.93 KB
/
DatabaseCopyActivationPrefCheck.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
## Please check GitHub repository for updates to that script: https://github.com/bezibaerchen/prtgscripts
########################### Add Exchange Shell##############################
$exchangeuri = "http://<fqdn_of_Exchange_Server_with_RemotePowerShell>/PowerShell"
$session = new-pssession `
-ConfigurationName "Microsoft.Exchange" `
-ConnectionUri $exchangeuri `
-Authentication Kerberos
import-pssession -Session $session -AllowClobber | out-null
##########################Define Variables & Strings########################
[String] $errMessage = $null
[Bool] $bolFailover = $False
$countwrong = 0
#########################Get The Databases##################################
$dbcopystatus = Get-MailboxDatabaseCopyStatus * | Sort-Object Name
ForEach ($dbcopy in $dbcopystatus)
{
$db = $dbcopy.name
$status = $dbcopy.status
$server = $dbcopy.MailBoxServer
$actpref = $dbcopy.ActivationPreference
# Compare the server where the DB is currently active to the server where it should be
If ($status -eq "Mounted" -and $actpref -ne "1")
{
$errMessage += "`n$($dbcopy.Name) has a mounted copy on $($dbcopy.MailboxServer) with Activation Preference $actpref"
$countwrong = $countwrong + 1
$bolFailover = $True
}
}
$errMessage += "`n`n"
if ($bolFailover) {
#$errMessage
##Write-Host "1"
##Write-Host "$errMessage"
$prefcheckstatus = "$errMessage"
##exit 2
}
Else
{
$prefcheckstatus = "All good. No misplaced DB(s) found..."
##Write-Host "0"
##Write-Host "All Good. No misplaced DB(s) found..."
##exit 0
}
"<prtg>
<result>
<channel>misplacedDBs</channel>
<value>$countwrong</value>
<showChart>1</showChart>
<showTable>1</showTable>
<unit>Count</unit>
<customunit>Misplaced DBs</customunit>
<mode>absolute</mode>
</result>
<text>$prefcheckstatus</text>
</prtg>"
remove-pssession -session $session