PoshCode Archive  Artifact [f88bb580b0]

Artifact f88bb580b05bc42b9f8450a93c508b36fbdaa6ff10f843f08dee40c29b327ad9:

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

# 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: 2727
# x-archived: 2016-03-06T11:41:50
# x-published: 2012-06-10T09:45:00
#
# Thanks Jeff for pointing out the error! Forgot the Param () piece that ties this all together as an advanced function.
#
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)"
    }
}