Last active
July 3, 2023 18:37
-
-
Save OmerMicrosoft/2e2cdeb92743ba07865f2575f8c26037 to your computer and use it in GitHub Desktop.
Get Installed Windows Roles on each Domain Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Get Installed Roles on each Domain Controller | |
$DCsInForest = (Get-ADForest).Domains | % {Get-ADDomainController -Filter * -Server $_} | |
$DCsRolesArray = @() | |
foreach ($DC in $DCsInForest) { | |
$DCRoles="" | |
$Roles = Get-WindowsFeature -ComputerName $DC.HostName | Where-Object {$_.Installed -like "True" -and $_.FeatureType -like "Role"} | Select DisplayName | |
foreach ($Role in $Roles) { | |
$DCRoles += $Role.DisplayName +"," | |
} | |
try {$DCRoles = $DCRoles.Substring(0,$DCRoles.Length-1)} | |
catch {$DCRoles = "Server roles cannot be obtain"} | |
$DCObject = New-Object -TypeName PSObject | |
Add-Member -InputObject $DCObject -MemberType 'NoteProperty' -Name 'DCName' -Value $DC.HostName | |
Add-Member -InputObject $DCObject -MemberType 'NoteProperty' -Name 'Roles' -Value $DCRoles | |
$DCsRolesArray += $DCObject | |
} | |
$DCsRolesArray | Out-GridView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment