Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-11-16
8
Medium Priority
?
115 Views
Last Modified: 2017-01-17
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 84

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 84

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
 

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here's a look at newsworthy articles and community happenings during the last month.
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

963 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