dantpro

ListAllDCRoles.ps1

Mar 8th, 2016
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://rcmtech.wordpress.com/2016/02/02/list-all-domain-controllers-and-roles-with-powershell/
  2.  
  3. $DCs = Get-ADDomainController -Filter *
  4. $Results = New-Object -TypeName System.Collections.ArrayList
  5. foreach($DC in $DCs){
  6.     [string]$OMRoles = ""
  7.     $ThisResult = New-Object -TypeName System.Object
  8.     Add-Member -InputObject $ThisResult -MemberType NoteProperty -Name Name -Value $DC.Name
  9.     Add-Member -InputObject $ThisResult -MemberType NoteProperty -Name Site -Value $DC.Site
  10.     Add-Member -InputObject $ThisResult -MemberType NoteProperty -Name IPv4Address -Value $DC.IPv4Address
  11.     Add-Member -InputObject $ThisResult -MemberType NoteProperty -Name OperatingSystemVersion -Value $DC.OperatingSystemVersion
  12.     Add-Member -InputObject $ThisResult -MemberType NoteProperty -Name IsGlobalCatalog -Value $DC.IsGlobalCatalog
  13.     Add-Member -InputObject $ThisResult -MemberType NoteProperty -Name IsReadOnly -Value $DC.IsReadOnly
  14.     foreach($OMRole in $DC.OperationMasterRoles){
  15.         $OMRoles += ([string]$OMRole+" ")
  16.     }
  17.     Add-Member -InputObject $ThisResult -MemberType NoteProperty -Name OperationMasterRoles -Value $OMRoles
  18.     $Results.Add($ThisResult) | Out-Null
  19. }
  20. $Results = $Results | Sort-Object -Property Site
  21. $Results | Format-Table -AutoSize
Advertisement
Add Comment
Please, Sign In to add comment