Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Change Titles and Dates in a powershell generated CSV File

Posted on 2016-08-18
2
Medium Priority
?
61 Views
Last Modified: 2016-08-18
I am using powershell to generate a CSV File. I am using Quest ActiveRoles. Not sure if that matters but figured I'd mention it. I am exporting a listing of AD users. Another program is going to ingest this file but there's a few problems. The date field is not formatted correctly. I need to shave off the time from the date. I was told the application requires the header names to be specific values. Is there a way to reformat the headers to be called something different?  The script is below

get-qaduser -SearchRoot "OU=San Diego,OU=domain,DC=domain,DC=com","OU=New York,OU=domain,DC=domain,DC=com" -enabled -SizeLimit 0 -NotMemberOf "Test Accounts","Service Accounts","Hitachi-ID Exclude" | Select Email,FirstName,LastName,Department,WhenCreated  | Export-Csv 'C:\Scripts\Active Directory\InfoSec-UserExport.txt' -NoClobber -NoTypeInformation -Force

The output I get is

"Email","FirstName","LastName","Department","whenCreated"
"User1@domain.com","UserF1","UserL1l","Cashiering","9/8/2006 11:33:53 AM"
"User2@domain.com","UserF2","UserL2l","Cashiering","9/13/2006 11:50:59 AM"
"User3@domain.com","UserF3","UserL3l","Cashiering","12/6/2012 2:51:43 PM"


In the "When Created" field, I need to shave off the time and just include the date MM/DD/YYYY.

these titles need to change from:
"Email","FirstName","LastName","Department","whenCreated"
To:
"emailAddress","firstName","lastName","Department","whenCreated"


I'm assuming I need to do an import-csv but not sure exactly how to go about editing a particular field in a CSV in each record and also modify the column headers :(



Thank you in advance!
0
Comment
Question by:jbla9028
[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: 41761271
You can do the work with calculated properties in the Select-Object command.  The below should work if the WhenCreated property is a datetime object (if not, a slight modification would be needed).
get-qaduser -SearchRoot "OU=San Diego,OU=domain,DC=domain,DC=com","OU=New York,OU=domain,DC=domain,DC=com" -enabled -SizeLimit 0 -NotMemberOf "Test Accounts","Service Accounts","Hitachi-ID Exclude" |
 Select @{n="EmailAddress";e={$_.Email}},
        FirstName,LastName,Department,
        @{n="WhenCreated";e={($_.WhenCreated).ToShortDateString()}} |
 Export-Csv 'C:\Scripts\Active Directory\InfoSec-UserExport.txt' -NoClobber -NoTypeInformation -Force

Open in new window

0
 
LVL 1

Author Closing Comment

by:jbla9028
ID: 41761409
Perfect. Thank you!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

598 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