Solved

Quest script not outputing in the correct format

Posted on 2014-03-19
2
312 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
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.

738 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