# --------------------------------------------------------------------------------------------------- # # Microsoft PowerShell Source File # NAME: GetFSMO.ps1 # # AUTHOR: Adam Bell, www.leadfollowmove.com # DATE : 03/01/2007 # # PURPOSE: Retrieve and display the FSMO roles for a domain/forest. # # COMMENT: Best viewed in Notepad2 # Sample code only. Educational purposes only. # # --------------------------------------------------------------------------------------------------- Set-Variable -name DS_BEHAVIOR_WIN2000 -value 0 -option constant Set-Variable -name DS_BEHAVIOR_WIN2003 -value 2 -option constant # --------------------------------------------------------------------------------------------------- function fnGetFSMORoles # --------------------------------------------------------------------------------------------------- { # Inputs: 1) Domain RootDSE object # Objective: 1) Retrieve the five FSMO roles for the domain/forest. # Returns: 1) an associative array containing the FSMO roles. Param ( $Domain ) $DomainDN = $Domain.defaultNamingContext $SchemaDN = $Domain.schemaNamingContext $ConfigDN = $Domain.configurationNamingContext $FSMO = @{} # PDC Emulator $PDC = [adsi]("LDAP://"+ $DomainDN) $FSMO = $FSMO + @{"PDC" = $PDC.fsmoroleowner} # RID Master $RID = [adsi]("LDAP://cn=RID Manager$,cn=system,"+$DomainDN) $FSMO = $FSMO + @{"RID" = $RID.fsmoroleowner} # Schema Master $Schema = [adsi]("LDAP://"+$SchemaDN) $FSMO = $FSMO + @{"Schema" = $Schema.fsmoroleowner} # Infrastructure Master $Infra = [adsi]("LDAP://cn=Infrastructure,"+$DomainDN) $FSMO = $FSMO + @{"Infra" = $Infra.fsmoroleowner} # Domain Naming Master $DN = [adsi]("LDAP://cn=Partitions,"+$ConfigDN) $FSMO = $FSMO + @{"DN" = $DN.fsmoroleowner} return $FSMO } # --------------------------------------------------------------------------------------------------- # System.DirectoryServices.PropertyValueCollection $role = (fnGetFSMORoles ([adsi]("LDAP://RootDSE"))) # Convert to System.String, and extract the second portion of the DN - which # is the server name. write-host "PDC:" $role.PDC.ToString().split(",")[1] write-host "RID:" $role.RID.ToString().split(",")[1] write-host "Schema:" $role.Schema.ToString().split(",")[1] write-host "Infra:" $role.Infra.ToString().split(",")[1] write-host "DN:" $role.DN.ToString().split(",")[1]