Follow-up on Active Directory schema versions

I published last year a function that helps determine the current Active Directory, Exchange Server and Lync schema version on this page.

Now that Windows 2012 Server R2 reached its general availability (GA), my function needs to be updated 😀

I’ve added the version for Windows 2012 R2, Exchange Server 2010 SP3.
I’ve removed to the code for loading the Active Directory module in the begin block and prefered to rely on the #requires statements for this purpose.

#Requires -Version 3.0
#Requires -Module ActiveDirectory

Function Get-ADSchemaVersion {
[CmdletBinding()]
param()
Begin {
    $KnownSchema = DATA {
    ConvertFrom-StringData @'
    13=Windows 2000 Server
    30=Windows Server 2003
    31=Windows Server 2003 R2
    44=Windows Server 2008
    47=Windows Server 2008 R2 
    56=Windows Server 2012 RTM
    69=Windows Server 2012 R2
    4397=Exchange Server 2000 RTM
    4406=Exchange Server 2000 SP3
    6870=Exchange Server 2003 RTM
    6936=Exchange Server 2003 SP3
    10628=Exchange Server 2007 RTM
    10637=Exchange Server 2007 RTM
    11116=Exchange 2007 SP1
    14622=Exchange 2007 SP2 or Exchange 2010 RTM
    14726=Exchange 2010 SP1
    14732=Exchange 2010 SP2
    14734=Exchange 2010 SP3
    15137=Exchange 2013 RTM
    1006=LCS 2005
    1007=OCS 2007 R1
    1008=OCS 2007 R2
    1100=Lync Server 2010
    1150=Lync Server 2013
'@
    }    
}
Process {
    try {
        $SchemaPartition = (Get-ADRootDSE -ErrorAction Stop).NamingContexts | Where-Object {$_ -like "*Schema*"} 
    } catch {
        Write-Warning -Message "Failed to find the AD naming context"
    }
    if ($SchemaPartition) {

        # Get the version of AD schema
        try {
            $SchemaVersionAD = (Get-ADObject $SchemaPartition -Property objectVersion -ErrorAction Stop).objectVersion
            New-Object -TypeName psobject -Property @{
                ProductName = "Active Directory"
                Version = $SchemaVersionAD
                Description = $KnownSchema[$SchemaVersionAD.ToString()]
            }
        } catch {
            Write-Warning -Message "Failed to query the AD schema version"
            break
        }
        # Get the version of Exchange
        try {
            $SchemaVersionExchange = (Get-ADObject "CN=ms-Exch-Schema-Version-Pt,$SchemaPartition" -Property rangeUpper -ErrorAction Stop).rangeUpper
            New-Object -TypeName psobject -Property @{
                ProductName = "Exchange"
                Version = $SchemaVersionExchange
                Description = $KnownSchema[$SchemaVersionExchange.ToString()]
            }
        } catch {
            Write-Warning -Message "Schema version for Exchange not found"
        }

        # Get the version of Lync
        try {
            $SchemaVersionLync = (Get-ADObject "CN=ms-RTC-SIP-SchemaVersion,$SchemaPartition" -Property rangeUpper -ErrorAction Stop).rangeUpper
            New-Object -TypeName psobject -Property @{
                ProductName = "Lync"
                Version = $SchemaVersionLync
                Description = $KnownSchema[$SchemaVersionLync.ToString()]
            }
        } catch {
            Write-Warning -Message "Schema version for Lync not found"
        }
  
    }
}
End {}
}

Get-ADSchemaVersion | Select ProductName,Version,Description | ft -AutoSize
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s