PoshCode Archive  Artifact [cbb918a5b8]

Artifact cbb918a5b8187743cfeba6e61cd196cb9e0c884e765ee24007db52d5c5b4da21:

  • File Get-FSMORoleOwner.ps1 — part of check-in [b9b4f77ed8] at 2018-06-10 13:14:53 on branch trunk — This advanced function will get all FSMO role owners for each domain in a forest. Returns an object that contains the collection of FSMO role owners. (user: Boe Prox size: 2423)

# encoding: ascii
# api: powershell
# title: Get-FSMORoleOwner
# description: This advanced function will get all FSMO role owners for each domain in a forest. Returns an object that contains the collection of FSMO role owners. 
# version: 0.1
# type: function
# author: Boe Prox
# license: CC0
# function: Get-FSMORoleOwner
# x-poshcode-id: 2726
# x-derived-from-id: 2727
# x-archived: 2016-03-23T04:59:51
# x-published: 2012-06-10T09:44:00
#
# Thanks Jeff for pointing out the error! Forgot the Param () piece that ties this all together as an advanced function.
# The cmdletbinding line threw an error
# Unexpected attribute ‘cmdletbinding’.
# At line:24 char:15
# + [cmdletbinding <<<< ()]
# + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
# + FullyQualifiedErrorId : UnexpectedAttribute
#
Function Get-FSMORoleOwner {
<#  
.SYNOPSIS  
    Retrieves the list of FSMO role owners of a forest and domain  
    
.DESCRIPTION  
    Retrieves the list of FSMO role owners of a forest and domain
    
.NOTES  
    Name: Get-FSMORoleOwner
    Author: Boe Prox
    DateCreated: 06/9/2011  

.EXAMPLE
    Get-FSMORoleOwner
    
    DomainNamingMaster  : dc1.rivendell.com
    Domain              : rivendell.com
    RIDOwner            : dc1.rivendell.com
    Forest              : rivendell.com
    InfrastructureOwner : dc1.rivendell.com
    SchemaMaster        : dc1.rivendell.com
    PDCOwner            : dc1.rivendell.com
    
    Description
    -----------
    Retrieves the FSMO role owners each domain in a forest. Also lists the domain and forest.  
          
#>
[cmdletbinding()]
Param ()
Try {
    $forest = [system.directoryservices.activedirectory.Forest]::GetCurrentForest() 
    ForEach ($domain in $forest.domains) {
        $forestproperties = @{
            Forest = $Forest.name
            Domain = $domain.name
            SchemaMaster = $forest.SchemaRoleOwner
            DomainNamingMaster = $forest.NamingRoleOwner
            RIDOwner = $Domain.RidRoleOwner
            PDCOwner = $Domain.PdcRoleOwner
            InfrastructureOwner = $Domain.InfrastructureRoleOwner
            }
        $newobject = New-Object PSObject -Property $forestproperties
        $newobject.PSTypeNames.Insert(0,"ForestRoles")
        $newobject
        }
    }
Catch {
    Write-Warning "$($Error)"
    }
}