Solved

get-quadgroup and get-qadgroupmember: empty data when using -exportcsv (Powershell version 4)

Posted on 2016-11-16
8
25 Views
Last Modified: 2016-11-18
I am attempting to create a csv file which grabs all the groups and membership from Active Directory to a csv file. My goal is to list all users and the groups that they are members of. This may not be the best script. If you have a suggestion for a different script, I would be glad to see your suggestions.

When I run this command in Powershell I can see all the groups.

Add-PSSnapin Quest.ActiveRoles.ADManagement
get-qadgroup -Identity '* *' | foreach-object {
"`nGroup: $($_.name)"
get-qadgroupmember ($_)
}


However, when I add the -exportcsv command, the csv file is empty. I do see an error at multiple locations in the Powershell window while the command is running. The error is:

get-qadgroupmember : The trust relationship between the primary domain and the trusted domain failed.
At line:4 char:1
+ get-qadgroupmember ($_)
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-QADGroupMember], SystemException
    + FullyQualifiedErrorId : System.SystemException,Quest.ActiveRoles.ArsPowerShellSnapIn.Powershell.Cmdlets.GetGroupMemberCmdlet
0
Comment
Question by:Intelli-Seeker
  • 6
  • 2
8 Comments
 

Author Comment

by:Intelli-Seeker
ID: 41890360
I think I fixed the trust relationship issue. There were some orphaned objects from an old domain. I ran the same script and now the file only has this listed:

#TYPE System.String
"Length"
"20"


What am I missing? It shows on the powershell window if I do not pipe it to a csv.
0
 
LVL 78

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 41890447
why are you not using the native comands

get-adgroup -Identity '* *' | select-object name | foreach-object {
     get-adgroupmember ($_)
}

Open in new window

0
 

Author Comment

by:Intelli-Seeker
ID: 41890513
The command you suggested above outputs the following error:

get-adgroup : The term 'get-adgroup' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ get-adgroup -Identity '* *' | select-object name | foreach-object {
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (get-adgroup:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 41890558
do you have the RSAT tools installed on that computer as it should have automatically done the 'import-module activedirectory '
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Intelli-Seeker
ID: 41891437
I do not have RSAT installed. I am running the script on a Windows 2012 R2 server. Do I need that installed on the server where I am running the script?
0
 

Author Comment

by:Intelli-Seeker
ID: 41893086
I found a similar post to what you are suggesting (thanks for leading me in this direction).

The post is located here Powershell script Export list of all users and there group membership and export to CSV.

Now my question regarding this is how do I add more properties besides the DisplayName and memberof? For example, I would like to include the EmployeeId attribute that is in Active Directory.
0
 

Author Comment

by:Intelli-Seeker
ID: 41893327
This forum is awesome! Thanks for your help. I figured out the script with your guidance and the script found in another post. Here is the final version of the script (with the searchbase container names redacted).

Import-Module Activedirectory
Get-ADUser -Filter * -Properties DisplayName,EmployeeID,memberof -searchbase 'OU=Users,OU=WCNB,DC=wcnb,DC=local' | % {
  New-Object PSObject -Property @{
      UserName = $_.DisplayName
      EmployeeID = $_.EmployeeID
      Groups = ($_.memberof | Get-ADGroup | Select -ExpandProperty Name) -join ","
      }
} | Select UserName,EmployeeID,Groups | Export-Csv C:\Reports\ADreport.csv -NTI

Open in new window

0
 

Author Closing Comment

by:Intelli-Seeker
ID: 41893329
Thanks for your assistance in pointing me in the right direction. I had to install the AD feature on the server where I was running the script. After that I was able to create the script that I listed in the comments.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Join & Write a Comment

Suggested Solutions

Set OWA language and time zone in Exchange for individuals, all users or per database.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now