-
Notifications
You must be signed in to change notification settings - Fork 10
/
get-ExchangeSchemaVersion.ps1
89 lines (63 loc) · 3.45 KB
/
get-ExchangeSchemaVersion.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<#
.SYNOPSIS
This function gets the range upper for the exchange schema versions.
.DESCRIPTION
This function gets the range upper for the exchange schema versions.
.OUTPUTS
Returns the range upper of the Exchange schema versions.
.EXAMPLE
get-ExchangeSchemaVersion -globalCatalogServer $GC -adCredential $cred
#>
Function get-ExchangeSchemaVersion
{
[cmdletbinding()]
Param
(
[Parameter(Mandatory = $true)]
[string]$globalCatalogServer,
[Parameter(Mandatory = $true)]
$adCredential,
[Parameter(Mandatory = $false)]
[ValidateSet("Basic","Negotiate")]
$activeDirectoryAuthenticationMethod="Negotiate"
)
out-logfile -string "Output bound parameters..."
#Output all parameters bound or unbound and their associated values.
write-functionParameters -keyArray $MyInvocation.MyCommand.Parameters.Keys -parameterArray $PSBoundParameters -variableArray (Get-Variable -Scope Local -ErrorAction Ignore)
Out-LogFile -string "********************************************************************************"
Out-LogFile -string "BEGIN get-exchangeSchemaVersion"
Out-LogFile -string "********************************************************************************"
out-logfile "Getting the exchange schema version to determine what property set will be cleared during disablment."
$functionADRootDSE = $null
$functionExchangeSchemaVersion = $null #Exchange schema version detected from AD.
$functionSchemaNamingContext=$null #AD Schema context.
$functionExchangeSchemaContext = $null #Calculated exchange schema location.
$functionExchangeSchemaObject= $null
$functionExchangeRangeUpper = $null
try{
$functionADRootDSE=Get-ADRootDSE -server $globalCatalogServer -credential $adCredential -authType $activeDirectoryAuthenticationMethod -errorAction STOP
out-logfile -string "The AD Root Schema:"
out-logfile -string $functionADRootDSE
}
catch
{
out-logfile -string "Unable to get AD Root DSE."
}
$functionSchemaNamingContext=($functionADRootDSE).SchemaNamingContext
out-logfile -string ("The functionSchemaNamingContext is :"+$functionSchemaNamingContext)
$functionExchangeSchemaContext = "CN=ms-Exch-Schema-Version-Pt," + $functionSchemaNamingContext
out-logfile -string ("The functionExchangeSchemaContext is: "+$functionExchangeSchemaContext)
try{
$functionExchangeSchemaObject = Get-AdObject $functionExchangeSchemaContext -server $globalCatalogServer -credential $adCredential -authType $activeDirectoryAuthenticationMethod -properties * -errorAction STOP
out-logfile -string ("The Exchange Schema Object is: ")
out-logfile -string $functionExchangeSchemaObject
}
catch{
out-logfile -string ("Unable to retrieve the Exchange Schema object.")
}
$functionExchangeRangeUpper = $functionExchangeSchemaObject.rangeUpper
out-logfile -string ("The range upper of the Exchange Schema: "+$functionExchangeRangeUpper)
Out-LogFile -string "END get-exchangeSchemaVersion"
Out-LogFile -string "********************************************************************************"
return $functionExchangeRangeUpper
}