Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get-ADGroup - Group Name, ManagedBy Name and Email

Tags:

powershell

I'm looking to get the the Group Name, Managed By Name and Managed by Email in a PowerShell query similar to this.

Get-ADGroup -filter {Name -like "*Admins" }

The output would look something similar to:

Group Name | Managed By Name | Managed By Email

The issue I'm having is with joining Get-ADGroup and Get-ADUser. In SQL this "join" would happen on get-adgroup.managedby = get-aduser.distinguishedname. I know that's not how it works in Powershell, just thought I'd throw out an example of what I'm trying to do.

Any help would both be welcomed and appreciated.

like image 749
Rob Avatar asked Jan 26 '16 18:01

Rob


People also ask

How do I get the group name in PowerShell?

The Get-ADGroup cmdlet gets a group or performs a search to retrieve multiple groups from an Active Directory. The Identity parameter specifies the Active Directory group to get. You can identify a group by its distinguished name (DN), GUID, security identifier (SID), or Security Accounts Manager (SAM) account name.

How do I get a list of Active Directory groups?

Use Get-ADGroupMember cmdlet to List Members of an Active Directory Group. The PowerShell Get-ADGroupMember cmdlet is used to list the members of an Active Directory group. You can just type the cmdlet in a PowerShell window and you'll be prompted to enter the name of the group you want to use.

How do I find AD group owner in PowerShell?

To find AD groups with PowerShell, you can use the Get-ADGroup cmdlet. With no parameters, Get-ADGroup will query AD and return all groups in a domain using the Filter parameter. The Filter parameter is required.


1 Answers

I see @Mathias R. Jessen beat me to it, but here's what I had:

Get-ADGroup -filter {Name -like "*IT*" } -Properties managedBy |
ForEach-Object { 
$managedBy = $_.managedBy;

if ($managedBy -ne $null)
{
 $manager = (get-aduser -Identity $managedBy -Properties emailAddress);
 $managerName = $manager.Name;
 $managerEmail = $manager.emailAddress;
}
else
{
 $managerName = 'N/A';
 $managerEmail = 'N/A';
}

Write-Output $_; } |
Select-Object @{n='Group Name';e={$_.Name}}, @{n='Managed By Name';e={$managerName}}, @{n='Managed By Email';e={$managerEmail}}
like image 89
dugas Avatar answered Oct 10 '22 18:10

dugas