Solved

Quest script not outputing in the correct format

Posted on 2014-03-19
2
306 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
2 Comments
 
LVL 39

Accepted Solution

by:
footech earned 500 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

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

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

757 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