Solved

When writing to csv file how to change the order of the columns

Posted on 2013-11-20
1
266 Views
Last Modified: 2013-11-21
I have the following code to write last names and first names to a csv file:

$TempArray = New-Object -TypeName PSObject -Property @{            
            LastName = $lname            
            FirstName = $fname                 
}  

$TempArray | Export-CSV C:\MyList.csv -NoType

Open in new window


When I open my csv, the columns are listed in the following order:

FirstName         LastName

Is there a way to programmatically ensure they are written:

LastName  FirstName

I do not want ot copy paste, I want it to be written this way programmatically
0
Comment
Question by:YZlat
[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
1 Comment
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 250 total points
ID: 39664327
Hi,
you have to use the select-object property in the right order:
$TempArray = New-Object -TypeName PSObject -Property @{            
            LastName = $lname            
            FirstName = $fname                 
}  

$TempArray | select-object -property LastName,FirstName | Export-CSV C:\MyList.csv -NoType 

Open in new window


HTH
Rainer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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...
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 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