# 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)"
}
}