Group Membership report script - Modify to change format of output

Hi all,
Slowly getting to grips with Powershell. Such a powerful tool.
I've been tasked to develop a reporting script that will output a list of members of a set of groups and have found one of the scripts here to be a great starting point.
So this is the script:
"Import-Module ActiveDirectory
cd AD:
$MemberList = New-Item -Type file -Force “C:\Scripts\GroupMembers.csv”
Import-Csv “C:\scripts\grps.csv” | ForEach-Object {
 $GName = $_.Samaccountname
 $group = Get-ADGroup $GName
 $group.Name | Out-File $MemberList -Encoding Unicode -Append
  foreach ($member in Get-ADGroupMember $group) {$member.SamaccountName | Out-File $MemberList -Encoding Unicode -Append}
$nl = [Environment]::NewLine | Out-File $MemberList -Encoding ASCII -Append
The output lists the group name and the members of said group using Sam account name.
Ideally I would like that the email address of the user be in the output instead of SAMACCOUNTNAME however I realise that this may not easily be achievable due to the output of get-adgroupmember.
I'd also like if the output contained each of the email addresseses of the group members to be on the same line seperated by a semicolon in one cell directly under the group name.
EG:
GROUPNAME1
[email protected];[email protected];[email protected]
GROUPNAME2
user15:mail.com
Etc
Can either of these requirements be achieved from modifying the script above and any help would be much appreciated.
Thanks for any assistance.

You're welcome, glad I could help out.
Here's the same code with some comments and syntax links:
# Import the CSV file and process each record
Import-Csv .\grps.csv | ForEach {
# Set the group name as a variable for easy use later
# This really isn't necessary, but I do it for easy reading
$groupName = $_.SamAccountName
# Get the group members of the current group and process each user
# The output of this loop will be stored in a single variable
$groupMembers = Get-ADGroupMember -Identity $groupName -Recursive | ForEach {
# Get the user account and select only the EmailAddress property
Get-ADUser -Identity $_.SamAccountName -Properties EmailAddress |
Select -ExpandProperty EmailAddress
# Create a hashtable from the data above
# The group members are sorted and then joined using ; as a delimiter
$props = @{
GroupName = $groupName
Members = ($groupMembers | Sort) -join ';'
# Create a new object based on the hashtable above
New-Object PsObject -Property $props
} | Select GroupName,Members | Export-Csv .\groupMemberships.csv -NoTypeInformation
# Select is used to ensure the correct column order and then an output CSV is created
http://ss64.com/ps/import-csv.html
http://ss64.com/ps/foreach-object.html
http://ss64.com/ps/get-adgroupmember.html
http://ss64.com/ps/get-aduser.html
http://ss64.com/ps/select-object.html
http://ss64.com/ps/syntax-hash-tables.html
http://ss64.com/ps/new-object.html
http://ss64.com/ps/export-csv.html
Don't retire TechNet! -
(Don't give up yet - 13,085+ strong and growing)

Similar Messages

  • Essbase report scripts

    Hi,
    Is it possible to make report scripts to the XML format in Essbase (using Report Script Editor)? I've only done report scripts, that is saved in .txt format.
    Thanks in advance!

    Hi, I wan't to export data by using report script editor, but the file that I get from that should be xml. Is it possible?

  • Report script will not finish

    We are running EAS report script via batch scripts using mxl. These report scripts have not changed and at the time of running, nothing else is runnign onthe server. The report scripts will run for about 10minutes (which nroamlly take about 15 to complete) and it stops and says "administrator has temporarily disables commands". we have ran the unlock utility and stopped and restarted the application and still face the same issue. No settings have been changed on the server and the same reports ranthis morning, yet error out this afternoon with no change. We are on 11.1.2 planning. Any ideas?

    kplum12 wrote:
    We are running EAS report script via batch scripts using mxl. These report scripts have not changed and at the time of running, nothing else is runnign onthe server. Did you checked the CPU memory usage while executing Report..?
    Is server busy with many connections (User sessions) ??
    (or)
    Did you feel slow when you are trying to retreive that time?
    Some times every thing works slow..like when we are trying to retreive the data it is processing forever..In that case,I have restarted my server and every thing works fine....
    Edited by: Prabhas on Aug 3, 2011 11:41 AM

  • Report script with attribute members

    <BR>In a report script, is there a way to output the attribute members associated with a base mbr. For example, the base member I'm interested in is item codes which is in a sparse dimension with 500k members. Each code has been tagged with 5 attribute members of buyer, warehouse, vendor, product line, and date of last receipt. Desired output is:<BR><BR>Item Code, Buyer, warehouse, vendor, product, and date of last receipt. <BR><BR>Right now I don't care about data at any intersections, rather I just want to output the various attributes associated with each item code. I tried doing dimbottom on items, buyers, warehouse, vendor, etc, but as expected the report would not run. <BR><BR>Thanks in advance for any suggestions.

    <p>Maybe you can use the Outline Extractor, you can download itsomewhere on this website...</p>

  • Check group membership and export result to file

    Hi everyone,
    Could you please assist?  I need a script that get's a samAccountName from a text or csv file, then checks if the user belongs to Group A or Group B or Group C.  If user belongs to group A, then output "Group A" and so on.  Sample
    output file:
    JDoe Group A
    JSmith Group B
    KSmith  Group C
    DDoe Group A Group B Group C
    Thanks in advance,

    Hi Phathuynh,
    We always recommend you can start your own script, and post the current script and the issue for a better response.
    In addition, you can also refer to the cmdlet "Get-ADGroupMember" to list the members in group, and the script below is for your reference:
    $output = @()
    $groups = "user1","user2"
    $array1 = Get-ADGroupMember Group1|select -ExpandProperty samaccountname
    $array2 = Get-ADGroupMember Group2|select -ExpandProperty samaccountname
    Foreach($u in $groups){
    $user = Get-ADUser $u|select -ExpandProperty samaccountname
    $param = @{"user" = $user
    "group A" = ""
    "group B" = ""}
    $p = New-Object Psobject -Property $param
    if ($array1 -contains $user){
    $p."group A"= "YES"
    if ($array2 -contains $user){
    $p."group B" = "YES"
    $output += $p
    $output
    The screenshot of result:
    If there is anything else regarding this issue, please feel free to post back.
    Best Regards,
    Anna Wang
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Changes to the public group membership cannot be saved. You do not have sufficient permission to perform this operation on this object.

    We have an existing Hybrid Setup
    On-Premise Exchange Version: Exchange 2010 SP3 RU1
    Users are being migrated to Exchange Online every day.
    We've read online that Distribution Group and Public Folder permissions and memberships cannot be modified by Exchange Online users, until and unless all DG and PFs are moved to Exchange online.
    I'd like to confirm the above part.
    -Tushar Shah

    Hello,
    These migrated users who are owners of the distribution group can't manage it in Microsoft Exchange Online, if you want to manage the distribution group, the distribution group owners need to use on-premises tools for Exchange Server such as the following:
    EMC and EMS, and then we need directory synchronization or other tools to sync the changes to Office 365.
    Even though all DG and PFs are moved to Exchange online, I'm afraid that we still need on-premises tools for Exchange Server :EMC and EMS.
    If you have any feedback on our support, please click
    here
    Cara Chen
    TechNet Community Support

  • Report of Groups owned along with group memberships for each group, all in a single .csv file

    Hello all,
    What I'm trying to do is generate a report of all groups owned by a specific user, along with the group memberships, and output it all to a single .csv file. In the .csv file, I would like to have the group names as the column headers, and underneath
    the group name, list all the members of the group down through the column. So for example, if User1 owns 3 groups, the output would look like:
    What I'm having trouble with is outputting the objects to the .csv using New-Object psobject, and I'm starting to wonder if there is an easier way to do this and my brain is just fried.
    Any ideas?

    OK so I can try and give some code here, but I'm asking more of a concept question about how PowerShell builds objects so I'm not sure it will help....
    $User = "User1"
    get-adgroup -filter {managedby -eq $user} -pr member | %{
    $_.name
    $_.member
    OK so this is a simple script that outputs a group name followed by the membership, all in a single column. What I would like is for the group names to each be the header of a column, and have the membership listed underneath. For example:
    Is this possible in PowerShell?

  • Design question: Change Group membership for a AD resource via SelfService

    Hi all,
    based on the OIM tutorials, I designed OIM that way that an end user can successfully request a resource. Is there a way to allow end users to modify their resource "subscriptions"? For example, I would like to allow end users to change their AD group memberships after the initial provision to the resource.
    From what I have learned from the tutorials, I would assume to create an AD group membership attribute in the user account profile form and propagate changes to that attribute back to AD.
    Or is there a way to allow end users to change their resource data directly under "My Resources" ?

    there is no concept of requesting a modification of an already provisoned account. Like you said this can be achieved thru an attribute on the user's profile and on changing that attribute, downstream applications can be propagated the new value.
    Typically if changes to an already proviisoned account needs to be done in oim and through oim, an oim admin goes to the user's resource profile and clicks on edit on the process form and can edit any data there. in case of ad groups, there will be a child process form that shows the groups that the user is a member of, you can insert(add) new groups or delete existing groups from there and save the form. In the proviisoning porcess of AD you will need to write a porcess task, which should add/remove the user from the specified group in AD on the trigger when a new group is added or an existing group is removed wehn the admin is modifying the user's AD process form/process child forms in oim.

  • Changed group membership in WGM 10.6.3 from the 10.6 server. The change takes overnight to work. Formerly ran WGM from my 10.6.8 mac (worked perfectly)  but now I am at 10.7.5 and must use WGM on the server. Has anyone else seen this behavior?

    Changed group membership in WGM 10.6.3 from the 10.6 server. The change takes overnight to work. Formerly ran WGM from my 10.6.8 mac (worked perfectly)  but now I am at 10.7.5 and must use WGM on the server. Has anyone else seen this behavior?

    Hi
    "Changed group membership in WGM 10.6.3 from the 10.6 server. The change takes overnight to work"
    If I've understood you correctly I've never known this or anything else to take that long? What were you trying to do exactly?
    "Formerly ran WGM from my 10.6.8 mac (worked perfectly)  but now I am at 10.7.5 and must use WGM on the server. Has anyone else seen this behaviour?"
    http://support.apple.com/kb/HT1822
    HTH?
    Tony

  • How to format 2 Category groups in Report Builder 3

    Hi,
    I have to group my report on 2 categories. The problem is it looks ugly and even after much tampering I can't seem to find a good way to display labels. I tried them vertically as well.
    Can anyone give me a good advice on how to format labels so they look good?
    Thanks

    Hi Agenteusa,
    According to your description, when creating a chart with two category groups, the label for the parent category group can’t display completely.
    In your scenario, the issue could cause by the length of detail category labels are short while the corresponding parent category group label is too long. One way to make parent category group labels display completely is stretching the chart to an appropriate
    width manually.
    Also you can apply dynamic width by give parameters, please refer to the link below:
    Charts with Dynamic Height or Width based on Categories/Data
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • User Group Membership change Alert

    As a system administrator, I will like to be alerted when a user's group membership has changed on the domain. Can Spiceworks compare the imported memberships in its database with AD and alert me when they do not match? Below is an image of the information that SW imports which could be used for this comparison.
    This topic first appeared in the Spiceworks Community

    Assuming you know the dn of the groups to remove the person from and add them to, and the dn of the person to move, you should be able to do something similar to:
    Attributes attrs = new BasicAttributes(true);
    Attribute uniquemember = new BasicAttribute("uniquemember");
    uniquemember.add("uid=user,o=domain.com"); //add user to move to attribute
    attrs.put(uniquemember);
    DirContext ctx = //connect to your ldap dir
    try{
         ctx.modifyAttributes(groupToRemoveFromDN, ctx.REMOVE_ATTRIBUTE, attrs);
         ctx.modifyAttributes(groupToAddToDN, ctx.ADD_ATTRIBUTE,attrs);
    catch (NamingException ne) {
         //return error appropriately
    try{
         ctx.close();
    catch (NamingException ne) {
         //do what you want with error
    }You also might want to check out the JNDI tutorial at http://java.sun.com/products/jndi/tutorial/index.html
    --Nicole

  • Invoke an adapter on change of User's Group Membership details

    Hi
    I need to invoke an adapter on change of User’s Group Membership details. I am not able to figure out from where I can invoke my adapter.
    Does anyone have any idea about this?
    -- Another Question: what is the purpose of having “tcUSRautoGroupMembership” in User’s Object Form on Post Update. It would be nice if you give some details about this task.
    -Hardew

    Thanks for quick response.
    What you have mentioned, is applicable for a specific value of a user’s OIM Profile filed; that means it will triggered only if a user has specified value i.e. "blah blah" for that field i.e. fieldA.
    However my scenario is slightly different. Let me explain my scenario by example:-
    I have N numbers of OIM groups i.e. g1, g2, g3, g4……, gn and a user called myUser. This user is a member of two groups’ g1 and g2, now if I make myUser to member of one more group i.e. g3 or remove i.e. g1; then I want to perform a custom task using adapter on this Group Membership change.
    Is there any “Data Object Form” where I can associate my adapter on post-update to detect change of User’s Group Membership?
    _hardew                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Scripting Group membership

    I have a ODM that has jut been added to AD. I have OD groups that I now need to add AD members to push MCX down to my clients, the problem is if I do it from WGM I'm only able to do one member at a time. This is not so bad when I have to do it to groups with about ten members, but it gets REALLY boring when I have groups with a large number of users. Seems this would be a great task to do from a script, has anyone done this or could lead me to some info on how to do it?

    Thanks for the reply.
    Will dseditgroup work with AD? After reading the man page for it I tried,
    dseditgroup -o read -n /Active\ Directory/All\ Domains/ testgroup
    *testgroup= Group we created in AD with about five users in it.
    After I hit enter the shell returns with nothing, not even a error. Do I have the syntax wrong or can I not use dseditgroup to read group membership from a AD group?

  • Com.apple.alf.plist file keeps changing group membership

    Hey All, I've read several discussions about this issue.  The com.apple.alf.plist file keeps changing group membership from admin to wheel.  Disk Utility repair changes the group membership to admin but it will change back to wheel during normal use of the computer, it seems that accessing systempreferences.app and security preferences will change the group to wheel. 
    I don't really want to get into a discussion about the wheel account, unless necessary, but since this is a very important system settings file I'd like it to work correctly.  I have noticed several issues with the firewall not responding as expected such as turning off by itself, and app settings changing or disappearing from the security preference pane.  So, I have deleted the plist file and restarted as recommended on other discussions but the issue always returns during normal use.  I think it might be the application owning the plist file causing the issue, but I am not sure which one owns the plist file.  I assume it would be systempreference.app since I think it is a firewall plist file. The permissions for systempreferences.app is strange also; 
    - everyone - custom
    - system    - read/write
    - wheel      - read/write
    - everyone  -read
    This may be the culprit but I tried to make a minor change, so as not to mess up the operating system, and disk utility repair permissions just puts it back the way it was.   Any ideas about this would be very appreciated.
    Note:  I have done a complete system reinstall and the issue still returns.

    OK, Since I haven't gotten any responses about this it must be a complicated issue.  Just as a quick check could some of you good people out there look at the "Get Info" window for the systempreferences.app and see if your permissions look like mine?  I'm still having trouble with the firewall settings not acting as expected such as apps and processes that I have approved/denid connection access not showing up in the firewall pane of system preferences and having to reapprove each startup.  Thank you in advance for any help on this.

  • Policies assigned to groups - membership changes not working

    I have a single ZESM IR8 server setup.
    All security throughout my environment, ZESM and otherwise, is based on group membership.
    If I change a user from one group to another group this change does not reflect in their policy assignment.
    Scenario: GroupA = standard user policy, GroupB = power user policy.
    UserA was first in Group A and therefore got the standard user policy.
    UserA now requires the power user policy.
    Remove UserA from GroupA and add UserA to GroupB (in iManager).
    UserA does NOT get the "power user" policy that is assigned to GroupB
    Am aware that I can assign the policy at a user level but this is NOT an option in my environment. All security assignments MUST happen at a group level.

    What you observed is the expected behavior.
    ZESM doesn't updates group membership in real time once a policy has been published. I've described this behavior on previous posts.
    What the MC does behind the scenes when you click "Publish" on a container or group object is to assign the policy individually to each member/user. For groups, it resolves membership at the time the policy is published then the MC iterates among each member assigning the policy to each of them. That's why you don't see updates once the policy is published.
    Try Updating the published policy to see if that works. From the docs:
    Updating a Published Policy
    Once a policy has been published to the user(s) or computer(s), simple updates can be maintained by editing the components in a policy, and re-publishing. For example, if the ZENworks Endpoint Security Management Administrator needs to change the WEP key for an access point, the adminstrator only needs to edit the key, save the policy, and click Publish. The affected end-users and computers receive the updated policy (and the new key) at their next check-in.
    >>>
    From: laurabuckley<[email protected]>
    To:novell.support.zenworks.endpoint-security-management
    Date: 12/15/2009 7:16 AM
    Subject: Policies assigned to groups - membership changes not working
    I have a single ZESM IR8 server setup.
    All security throughout my environment, ZESM and otherwise, is based on
    group membership.
    If I change a user from one group to another group this change does not
    reflect in their policy assignment.
    Scenario: GroupA = standard user policy, GroupB = power user policy.
    UserA was first in Group A and therefore got the standard user policy.
    UserA now requires the power user policy.
    Remove UserA from GroupA and add UserA to GroupB (in iManager).
    UserA does NOT get the "power user" policy that is assigned to GroupB
    Am aware that I can assign the policy at a user level but this is NOT
    an option in my environment. All security assignments MUST happen at a
    group level.
    laurabuckley
    laurabuckley's Profile: http://forums.novell.com/member.php?userid=122
    View this thread: http://forums.novell.com/showthread.php?t=395870

Maybe you are looking for

  • Mail going to spam folder

    All of my incoming mail keeps going into a spam folder. I've deleted the folder and relaunched mail and the folder returns.

  • Unable to recognize computers via target disk mode

    I am trying to transfer files from my iBook G4 to my new intel-based iMac. I have successfully engaged my iBook in target disk mode (i.e. the firewire symbol moving around the screen) but my iMac does not recognize that the iBook is in target disk mo

  • Database upgrade from 10.2.0.3.0 to 11.1.0.7

    Hi All, OS:linux 86x64 Red Hat linux We would like to perform Database upgrade from 10.2.0.3.0 to 11.1.0.7. I do have quick questions regarding the upgrade. 1. When we upgrade the Database to version 11, do we need to update the client also? What is

  • How to create page individual layers

    I am using inDesign CS5 version and with a 30 pages document. What I am looking foward is to create a new layer, but specifically to one one this 30 pages document, not for the hole document. Is it possible or when I create a new layer it will affect

  • Reason code 0X5006

    Hi all, Today my windows 2012 gets restarted automatically in the morning. Error code is 0X5006 and the process wininit.exe has initiated the restarted of computer ( server name ) on behalf of user for the following reasond. No title for this reason