?
Solved

Quest script not outputing in the correct format

Posted on 2014-03-19
2
Medium Priority
?
314 Views
Last Modified: 2014-03-19
Hi ALL !!

Can someone help me on why the output file does not have it in the order I want ?

I want in the order of:
UsrSAmAccountName,Name,Groups,GrpDescription

And its outputting in order:
UsrSAmAccountName,Groups,UserName,GrpDescription

Add-PSSnapin *Quest* -ErrorAction SilentlyContinue
$input= "e:\Projects\test\users.txt"
$Output = "e:\Projects\test\test_Groups.csv"
Get-Content $input | % {
$user = Get-QADUser -sAMAccountName $_
New-Object Psobject -Property @{"UsrSAmAccountName"=$user.SAmAccountName;"UserName"=$user.Name;"Groups"="";"GrpDescription"=""}

ForEach ($Group in $user.memberof) {
            $Grp= Get-QADGroup $group
            New-Object Psobject -Property @{"UsrSAmAccountName"=$user.SAmAccountName;"UserName"="";"Groups"=$Grp.Name;"GrpDescription"=$Grp.Description}
    }
} | Export-CSV -Path $Output -NoTypeInformation
0
Comment
Question by:MilesLogan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
footech earned 2000 total points
ID: 39941097
You need to add a Select-Object command in front of the Export-CSV and manually specify the order of columns you want.
 } | Select UsrSAmAccountName,Name,Groups,GrpDescription | Export-CSV -Path $Output -NoTypeInformation 

Open in new window


I can't say exactly why it chooses a particular order.  At one time I thought it was alphabetical according to the name of the property, but I don't believe that is right.  Haven't really investigated...
0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 39941114
That was it !! thanks so much !
0

Featured Post

Bringing Advanced Authentication to the SMB Market

WatchGuard announces the acquisition of advanced authentication provider, Datablink, with one mission – to bring secure authentication to SMB, mid-market, and distributed enterprises with a cloud-based solution, ideal for resale via their established channel & MSSP community.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Let's recap what we learned from yesterday's Skyport Systems webinar.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
Suggested Courses

770 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