PoshCode Archive  Artifact [fdb5c89bd7]

Artifact fdb5c89bd7ebde523d8b3926fefe8159e2e63342c8a923bb5fb7bf0445d0f6ca:

  • File Get-FSMORoleOwner.ps1 — part of check-in [d6da8a2b5f] at 2018-06-10 13:14:50 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: 2271)

# 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: 2724
# x-derived-from-id: 2726
# x-archived: 2016-06-20T23:52:20
# x-published: 2011-06-10T06:03:00
#
# 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.  
          
#>
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)"
    }
}