Home > other >  how to retrieve whole user's detail from group which contain "AZ-APP-office 365"
how to retrieve whole user's detail from group which contain "AZ-APP-office 365"

Time:10-16

We have few groups in AD for the O365 license.

what powershell script I can get to export all the users under E3 groups.

I was using below, but it only give me information for 365 E3 user only

Get-AdGroupMember -Identity "AZ-APP-Office 365 E3" -recursive | Where objectClass -eq "user" | Get-ADUser -Properties * | select-object displayName,samAccountName,UserPrincipalName,Mail,Manager,Department,Enabled | export-csv c:\temp\365\O365visioLicenseOctober.csv

what powershell script I can get to export all the users from the group which contains "E3.

enter image description here

CodePudding user response:

As Abraham suggested, first get the groups with names starting with 'AZ-APP-Office 365 E3'.

Then use a loop to get the info you need:

Get-ADGroup -Filter "Name -like 'AZ-APP-Office 365 E3*'" | ForEach-Object {
    $group = $_.Name
    $_ | Get-AdGroupMember -Recursive | 
         Where-Object {$_.objectClass -eq "user"} | 
         # Get-ADUser returns these properties by default:
         # DistinguishedName, Enabled, GivenName, Name, ObjectClass, ObjectGUID, SamAccountName, SID, Surname, UserPrincipalName
         # so only ask for the extra attributes with parameter '-Properties'
         Get-ADUser -Properties DisplayName, EmailAddress, Manager, Department | 
         Select-Object @{Name = 'Group'; Expression = {$group}}, 
                       DisplayName,SamAccountName,UserPrincipalName,EmailAddress,Manager,Department,Enabled
} | Export-Csv -Path 'c:\temp\365\O365visioLicenseOctober.csv' -NoTypeInformation
  • Related