1
+ <#
2
+ . SYNOPSIS
3
+ Get Exchange Server schema and version related information for an exisiting Exchange Organization
4
+
5
+ Thomas Stensitzki
6
+
7
+ THIS CODE IS MADE AVAILABLE AS IS, WITHOUT WARRANTY OF ANY KIND. THE ENTIRE
8
+ RISK OF THE USE OR THE RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
9
+
10
+ Version 1.0, 2018-05-22
11
+
12
+ . DESCRIPTION
13
+
14
+ This script gets the Exchange schema version from the Active Directory schema partition
15
+
16
+ The Exchange organization name is fetched from Active Directory automatically
17
+
18
+ The script fetches at forest level:
19
+ - objectVersion of MESO Container
20
+ - rangeUpper of ms-Exch-Schema-Version-Pt
21
+ - msExchProductId of Exchange Organization container
22
+ - objectVersion of Exchange Organization container
23
+
24
+ The script fetches at forest level:
25
+ - objectVersion of MESO Container
26
+
27
+ . LINK
28
+ http://scripts.granikos.eu
29
+
30
+ . NOTES
31
+ Requirements
32
+ - Windows Server 2012 R2, Windows Server 2016
33
+
34
+ Revision History
35
+ --------------------------------------------------------------------------------
36
+ 1.0 Initial release
37
+
38
+ . EXAMPLE
39
+ Fetch all version information in the Active Directory forest
40
+ .\Get-ExchangeServerVersionInfo.ps1
41
+ #>
42
+ [CmdletBinding ()]
43
+ param (
44
+ )
45
+
46
+ Import-Module - Name ActiveDirectory
47
+
48
+ # region Functions
49
+
50
+ function Get-ExchangeOrganizationName {
51
+ <#
52
+ . SYNOPSIS
53
+ This function fetches Exchange organization name from Active Directory configuration partition
54
+
55
+ . DESCRIPTION
56
+ The function determines the forest root domain and queries the Microsoft Exchange container
57
+ in the Active Directory configuration partition to get name of the msExchOrganizationContainer.
58
+ #>
59
+
60
+ # Get Active Directory Forest Distinguihsed Name
61
+ $ForestNameDN = Get-ADDomain - Identity (Get-ADDomain ).Forest | Select-Object - ExpandProperty DistinguishedName
62
+
63
+ # Fetch Exchange Services hive from Active Directory Configuration Partition
64
+ $Configuration = [ADSI ](' LDAP://CN=Microsoft Exchange,CN=Services,CN=Configuration,{0}' -f $ForestNameDN )
65
+
66
+ # Get Exchange Organization Name from Exchange Services hive
67
+ $OrganizationName = ($Configuration.psbase.children | Where-Object {$_.objectClass -eq ' msExchOrganizationContainer' }).Name
68
+
69
+ return $OrganizationName
70
+
71
+ }
72
+
73
+ function Get-ExchangeSchemaVersion {
74
+ <#
75
+ . SYNOPSIS
76
+ This function fetches the rangeUpper value from Exchange schema object ms-Exch-Schema-Version-Pt,CN=Schema
77
+
78
+ . DESCRIPTION
79
+ The function determines the forest root domain and connects to the schema partition to read the
80
+ rangeUpper value of the ms-Exch-Schema-Version-Pt object.
81
+ #>
82
+
83
+ # Get Active Directory Forest Distinguished Name
84
+ $ForestNameDN = Get-ADDomain - Identity (Get-ADDomain ).Forest | Select-Object - ExpandProperty DistinguishedName
85
+
86
+ # Get rangeUpper attribute
87
+ $RangeUpper = ([ADSI ](' LDAP://CN=ms-Exch-Schema-Version-Pt,CN=Schema,CN=Configuration,{0}' -f $ForestNameDN )).rangeUpper
88
+
89
+ return $RangeUpper
90
+
91
+ }
92
+
93
+ function Get-ExchangeDomainInformation {
94
+ <#
95
+ . SYNOPSIS
96
+ Fetches the objectVersion attribute value of the MESO container object.
97
+ Fetches the msExchProductId and objectVersion attributes of Exchange Organization object, if the domain is the forest root domain.
98
+
99
+ . DESCRIPTION
100
+ The script determines whether to domain is the forest root domain. If the domain is the forest root the script fetches the following attributes:
101
+ - MESO container objectVersion
102
+ - Exchange organization msExchProductId
103
+ - Exchange organization objectVersion
104
+
105
+ If the domain is not the forest root domain, the script fetches the following attribute:
106
+ - MESO container objectVersion
107
+
108
+ . PARAMETER DomainName
109
+ The Active Directory domain name of the domain to query
110
+
111
+ . PARAMETER ExchangeOrganizationName
112
+ The Exchange organization name
113
+
114
+ . EXAMPLE
115
+ Get-ExchangeDomainInformation -DomainName varunagroup.de -ExchangeOrganizationName Varuna-Group
116
+ Get the Exchange related domain information for Active Directory domain varunagroup.de and Exchange organization named Varuna-Group
117
+ #>
118
+
119
+ param (
120
+ [Parameter (Mandatory , HelpMessage = ' Active Directory Domain Name' )][string ]$DomainName ,
121
+ [Parameter (Mandatory , HelpMessage = ' Provide the Exchange Organization Name' )][string ]$ExchangeOrganizationName
122
+ )
123
+
124
+ $DomainDN = Get-ADDomain - Identity $DomainName | Select-Object - ExpandProperty DistinguishedName
125
+
126
+ # Get Active Directory Forest Distinguihsed Name
127
+ $ForestNameDN = Get-ADDomain - Identity (Get-ADDomain ).Forest | Select-Object - ExpandProperty DistinguishedName
128
+
129
+ # Get MESO Container object Version
130
+ $MESOObjectVersion = ([ADSI ](' LDAP://CN=Microsoft Exchange System Objects,{0}' -f $DomainDN )).objectVersion
131
+ Write-Host (' MESO Container objectVersion : {0}' -f $ ($MESOObjectVersion ))
132
+
133
+ if ($DomainDN -eq $ForestNameDN ) {
134
+
135
+ # Get Exchange ProductId (Version) of Exchange Organisation
136
+ $ConfigurationProductId = ([ADSI ](' LDAP://CN={0},CN=Microsoft Exchange,CN=Services,CN=Configuration,{1}' -f $ExchangeOrganizationName , $DomainDN )).msExchProductId
137
+ Write-Host (' Exchange Configuration msExchProductId : {0}' -f $ ($ConfigurationProductId ))
138
+
139
+ # Get Exchange ObjectVersion of Exchange Organisation
140
+ $ConfigurationObjectVersion = ([ADSI ](' LDAP://CN={0},CN=Microsoft Exchange,CN=Services,CN=Configuration,{1}' -f $ExchangeOrganizationName , $DomainDN )).objectVersion
141
+ Write-Host (' Exchange Configuration objectVersion : {0}' -f $ ($ConfigurationObjectVersion ))
142
+
143
+ }
144
+ }
145
+
146
+ # endregion
147
+
148
+ # # MAIN ##########################################
149
+
150
+ # Write forest root domain
151
+ Write-Host
152
+ Write-Host " Exchange Server Schema and Object Information for forest [$ ( (Get-ADForest ).Name.ToUpper()) ]" - ForegroundColor Gray
153
+
154
+ # Fetch Exchange Organization name
155
+ $ExchangeOrgName = Get-ExchangeOrganizationName
156
+ Write-Host (' Exchange Organization Name : {0}' -f $ExchangeOrgName )
157
+
158
+ # Write Exchange schema version
159
+ Write-Host (' Active Directory Schema rangeUpper: {0}' -f (Get-ExchangeSchemaVersion ))
160
+
161
+ # Fetch all domains in the forest
162
+ $ForestDomains = (Get-ADForest ).Domains
163
+
164
+ foreach ($Domain in $ForestDomains ) {
165
+
166
+ Write-Host
167
+ Write-Host (' Working on {0}' -f ($Domain.ToUpper ()))
168
+
169
+ # Get domain related information
170
+ Get-ExchangeDomainInformation - DomainName $Domain - ExchangeOrganizationName $ExchangeOrgName
171
+
172
+ }
0 commit comments