≡ Menu

How to get FSMO roles of a active directory domain using powershell

I feel this post doesn’t require much explanation. We all know FSMO roles and their important. This little powershell script helps you query active directory FSMO roles from your domain/forest.

I have seen some more examples about the same topic in internet but all of them are using dotnet objects to get this information or running the command lines and parsing the information to generate the data. I feel this is not necessary as the built-in activedirectory module is providing this information in a very straight forward way.

function Get-AdFSMORoles {            
[cmdletbinding()]            
param()            

$AdFSMORoles = New-Object -TypeName PSobject            

import-module activedirectory            
$DomainRoles = Get-ADDomain            
$ForestRoles = Get-ADForest            

$AdFSMORoles | Add-Member -MemberType NoteProperty -Name InfraStructureMaster -Value $DomainRoles.InfraStructureMaster            
$AdFSMORoles | Add-Member -MemberType NoteProperty -Name RIDMaster -Value $DomainRoles.RIDMaster            
$AdFSMORoles | Add-Member -MemberType NoteProperty -Name PDCEmulator -Value $DomainRoles.PDCEmulator            
$AdFSMORoles | Add-Member -MemberType NoteProperty -Name SchemaMaster -Value $ForestRoles.SchemaMaster            
$AdFSMORoles | Add-Member -MemberType NoteProperty -Name DomainNamingMaster -Value $ForestRoles.DomainNamingMaster            

$ADFSMORoles | fl            
}

Hope this helps…

 

Comments on this entry are closed.

  • ucguy October 5, 2012, 10:12 pm

    clean and simple ( and native!) well done!

  • Daz November 28, 2012, 3:11 am

    Hi,

    How can I run this command? I copy and paste in a file and name the file file.ps1
    When I run it, nothing happens.

    Thanks so much.

    • Sitaram Pamarthi November 28, 2012, 8:51 pm

      instead of copy-pasting to file, do it to Powershell console itself and then run the function shown like below from the same powershell prompt.

      PS:\>Get-AdFSMORoles

      …and you will get the output.