Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Adjust output format for Ad MemberOf Code :

$
0
0

Hi Experts,

Here is a code that fetches me group membership of a user's AD account however when I fetch out data for a list of users output becomes bit tedious and needs lots of manual efforts to sort , I need the format to be updated as required , please suggest ?

Import-Module ActiveDirectory
$Users = get-content c:\ad\UserDNs.txt
ForEach ($User In $Users)
{
  "User: $User"


Write-host "working on $User"
$User.name
$name = $user | Out-File "c:\ad\memberof.txt" -append
Get-ADUser -identity $user -Properties mail | select mail | Out-File "C:\ad\memberof.txt" -append

Get-ADPrincipalGroupMembership -Identity $User | Select Name | Out-File "C:\ad\memberof.txt" -append
}

Here is the current output format of code:

User's_samAccount_name
mail                                                                                                                   
----                                                                                                                   
user@Mydomain.com                                                                                          
Name                                                                                                                   
----                                                                                                                   
DomainUsers                                                                                                           
System Administrators                                                                                       
Outlook users                                                                                                           

What’s desired is to have the member info INLINE with the distribution Groups like this:

Member OF :                                                                                                                  
----                                                                                                                   
DomainUsers                                                                                                          User's_samAccount_name        user@Mydomain.com                                                                                               
System AdministratorsUser's_samAccount_name   user@Mydomain.com                                                                                               
outlook usersUser's_samAccount_name           user@Mydomain.com                                                                                               


Aditya Mediratta


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>