[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Quest script not outputing in the correct format

Posted on 2014-03-19
2
Medium Priority
?
317 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 41

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  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

Let's recap what we learned from yesterday's Skyport Systems webinar.
Wouldn't it be nice if objects in Active Directory automatically moved into the correct Organizational Units? This is what AutoAD aims to do and as a plus, it automatically creates Sites, Subnets, and Organizational Units.
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

656 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