none
Powershell Script that outputs AD users account info RRS feed

  • Question

  • Hi,

    I wanted to be able to output all AD users, their assigned user groups(group membership), their description and OUs.

    Still learning power-shell, but I am not too good yet. So if anyone can help with this, I would appreciate it.

    Thanks in advance.

    Monday, April 11, 2016 8:31 PM

Answers

  • Update:


    Get-ADUser -Filter { sAMAccountName -like "*" } -Properties memberOf | ForEach-Object {
      $sAMAccountName = $_.SamAccountName
      $_.memberOf | ForEach-Object {
        New-Object PSObject -Property @{
          "user" = $sAMAccountName
          "memberOf" = $_
        }
      }
    }
    


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_StewartModerator Tuesday, April 12, 2016 6:11 PM
    • Marked as answer by bb1876 Tuesday, April 12, 2016 6:50 PM
    Tuesday, April 12, 2016 5:31 PM
    Moderator

All replies

  • Start by reading the following:

    This forum is for scripting questions rather than script requests


    -- Bill Stewart [Bill_Stewart]

    Monday, April 11, 2016 8:37 PM
    Moderator
  • not sure what you're trying to say there...
    Monday, April 11, 2016 8:56 PM
  • The link is self-explanatory.


    -- Bill Stewart [Bill_Stewart]

    Monday, April 11, 2016 9:11 PM
    Moderator
  • not sure what you're trying to say there...

    What Bill is saying is that this forum dont accept script requests 
    You have to post your code and ask specific questions about what is not working
    My recommendation to you as many people here, is to learn powershell, learn the AD cmdlets and you will find in a few days that your question is not that complicated, try to create a script to get a piece of the puzzle, then the other, that will make you practice and practice till you become a master powershell jedi, haha jk but seriously continue with your powershell learning and post whenever you feel ready but dont forget to also post your code

    Regards

    Monday, April 11, 2016 9:13 PM
  • understood. I actually have something, but it isn't doing what i wanted it do

    I will post it.

    Monday, April 11, 2016 9:16 PM
  • Make sure that your example contains only the minimum amount of code needed to reproduce the problem.


    -- Bill Stewart [Bill_Stewart]

    Monday, April 11, 2016 9:47 PM
    Moderator
  • Ok, here the script that I tired to use. But it keeps returning error. As you can see this is  only meant to export group membership.

    get-aduser -filter { CN -eq "username" } -searchbase 'OU=Enduser, OU=##, dc=##, dc=####, dc=###' -properties memberof |
    select samaccountname, @{name="MemberOf";expression={$_.memberof -join "`n"}} |
    export-csv "c:\users.csv"

    Monday, April 11, 2016 9:58 PM
  • You want to get the group membership of a single user. Is that correct? If so:


    $sAMAccountName = "username"
    Get-ADUser $sAMAccountName -properties memberOf |
      Select-Object -ExpandProperty memberOf | ForEach-Object {
        New-Object PSObject -Property @{
          "user" = $sAMAccountName
          "memberOf" = $_
        }
    }
    


    -- Bill Stewart [Bill_Stewart]

    Tuesday, April 12, 2016 2:23 PM
    Moderator
  • Thanks for responding. No, actually I want the output to show group membership of

    all users...Hence, the need to create a script....

    Tuesday, April 12, 2016 5:02 PM
  • I guess i can replace "username" and see if that does the work...
    Tuesday, April 12, 2016 5:03 PM
  • Update:


    Get-ADUser -Filter { sAMAccountName -like "*" } -Properties memberOf | ForEach-Object {
      $sAMAccountName = $_.SamAccountName
      $_.memberOf | ForEach-Object {
        New-Object PSObject -Property @{
          "user" = $sAMAccountName
          "memberOf" = $_
        }
      }
    }
    


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Bill_StewartModerator Tuesday, April 12, 2016 6:11 PM
    • Marked as answer by bb1876 Tuesday, April 12, 2016 6:50 PM
    Tuesday, April 12, 2016 5:31 PM
    Moderator
  • That worked. I was able to export group membership to csv file.

    thanks for the help.

    Tuesday, April 12, 2016 6:09 PM