Schema version using PowerShell

 

I’ve just played with PowerShell in my test environment and I was wondering if it’s possible to verify Active Directory Schema version in some simple way using it. As I know that schema version number is stored in objectVersion attribute of

"cn=Schema,cn=Configuration,dc=domain,dc=local" object

I found that there is in PowerShell cmd-let which allows to query that object and get its attributes

So,you need to simply type below syntax of cmd-let to get version of schema in a domain

for Windows PowerShell (available when you have at least one Domain Controller based on Windows Server 2008R2)

Get-ADObject -Identity "cn=Schema,cn=Configuration,dc=testenv,dc=local" -Properties * | Select objectVersion

Schema version using Windows PowerShell

for Quest PowerShell (required download from 3rd party website. This is free tool)

Get-QADObject -Identity "cn=Schema,cn=Configuration,dc=testenv,dc=local" -IncludeAllProperties | Select objectVersion

Schema version using Quest PowerShell

as you can see, this was very short and quick way to get information about schema version 🙂 However, I went one step further and I prepared some script which checks objectVersion and writes on the screen its OS name. Basically, I started with if syntax but it was not the best possible solution for that. I started looking in the Internet if there is something like “case” which I remember from Turbo Pascal 😀 … and I found … this is switch in PowerShell. So, after I used switch, my code looks better and I’ve decided to share it here 🙂 (perhaps someone would find it useful)

Below you can find complete script code for Windows and Quest PowerShell

Windows PowerShell module for Active Directory

Import-Module ActiveDirectory

Clear-Host
Write-Host ""

Write-Host "Schema version is " -ForegroundColor Green -NoNewLine

$schema_ver=Get-ADObject -Identity "cn=Schema,cn=Configuration,dc=testenv,dc=local" -Properties * | Select objectVersion

switch ($schema_ver.objectVersion)
 {

 13 { Write-Host "Windows 2000 Server" -ForegroundColor Yellow }
 30 { Write-Host "Windows Server 2003" -ForegroundColor Yellow }
 31 { Write-Host "Windows Server 2003 R2" -ForegroundColor Yellow }
 44 { Write-Host "Windows Server 2008" -ForegroundColor Yellow }
 47 { Write-Host "Windows Server 2008 R2" -ForegroundColor Yellow }
 51 { Write-Host "Windows Server 8 Developers Preview" -ForegroundColor Yellow }
 52 { Write-Host "Windows Server 8 Beta" -ForegroundColor Yellow }
 56 { Write-Host "Windows Server 2012" -ForegroundColor Yellow }
 69 { Write-Host "Windows Server 2012 R2" -ForegroundColor Yellow }
 72 { Write-Host "Windows Server Technical Preview (2014)" -ForegroundColor Yellow }
 81 { Write-Host "Windows Server Technical Preview 2 (2015)" -ForegroundColor Yellow }
 82 { Write-Host "Windows Server 2016 Technical Preview 3 (2015)" -ForegroundColor Yellow }
 85 { Write-Host "Windows Server 2016 Technical Preview 4 (2015)" -ForegroundColor Yellow }
 87 { Write-Host "Windows Server 2016" -ForegroundColor Yellow }
default { Write-Host "unknown - "$schema_ver.objectVersion -ForegroundColor Red }  }  Write-Host ""

Copy above code and paste it to notepad, save as ps1  file and you will be able to execute it in your environment (remember that you need to change distinguished name of a domain from dc=testenv,dc=local to yours)

Script based on Windows PowerShell

Quest PowerShell module for Active Directory

Clear-Host
Write-Host ""

Write-Host "Schema version is " -ForegroundColor Green -NoNewLine

$schema_ver=Get-QADObject -Identity "cn=Schema,cn=Configuration,dc=testenv,dc=local" -IncludeAllProperties | Select objectVersion

switch ($schema_ver.objectVersion)
{

13 { Write-Host "Windows 2000 Server" -ForegroundColor Yellow }
30 { Write-Host "Windows Server 2003" -ForegroundColor Yellow }
31 { Write-Host "Windows Server 2003 R2" -ForegroundColor Yellow }
44 { Write-Host "Windows Server 2008" -ForegroundColor Yellow }
47 { Write-Host "Windows Server 2008 R2" -ForegroundColor Yellow }
51 { Write-Host "Windows Server 8 Developers Preview" -ForegroundColor Yellow }
52 { Write-Host "Windows Server 8 Beta" -ForegroundColor Yellow }
56 { Write-Host "Windows Server 2012" -ForegroundColor Yellow }
69 { Write-Host "Windows Server 2012 R2" -ForegroundColor Yellow }
72 { Write-Host "Windows Server Technical Preview (2014)" -ForegroundColor Yellow }
81 { Write-Host "Windows Server Technical Preview 2 (2015)" -ForegroundColor Yellow }
82 { Write-Host "Windows Server 2016 Technical Preview 3 (2015)" -ForegroundColor Yellow }
85 { Write-Host "Windows Server 2016 Technical Preview 4 (2015)" -ForegroundColor Yellow }
87 { Write-Host "Windows Server 2016" -ForegroundColor Yellow }
default { Write-Host "unknown - "$schema_ver.objectVersion -ForegroundColor Red }  }  Write-Host ""

Copy above code and paste it to notepad, save as ps1  file and you will be able to execute it in your Quest PowerShell environment (remember that you need to change distinguished name of a domain from dc=testenv,dc=local to yours)

Script for Quest PowerShell

I hope it would be useful for you.

Next part >>>

Author: Krzysztof Pytko

Facebooktwittergoogle_plusredditpinterestlinkedinmail

4 responses to “Schema version using PowerShell”

  1. Mauro Rita says :

    You can add 69 for Windows Server 2012 R2 Preview 🙂

     
    • iSiek says :

      Thank you Mauro for information!
      I’ve checked this yesterday in my home lab and I will update posts on my blog with new Schema version.

      Regards,
      Krzysztof

       

Leave a Reply

Your email address will not be published. Required fields are marked *