Solved

add date to cvs report in Powershell

Posted on 2013-11-07
7
756 Views
Last Modified: 2013-11-08
HI - need to know how to add today's date in a report that I export to a csv file. I am very green in PowerShell and the person who wrote the report left our company. I am trying to re-fine it to fit my needs.
here is the script if anyone can help it would be great!
function iid($acct)
{
            if ($acct -eq 514)
            {$acctstat = "Disabled"}
            if ($acct -eq 512)
            {$acctstat = "Enabled"}
            return $acctstat
}
New-Item c:\shell\reports\UserReport.csv -type file -Force
Get-ADUser -Filter * -SearchBase "OU=**,DC=***,DC=***,DC=***" -Properties CN,LastLogonDate,WhenChanged,userAccountControl | Select-Object CN,LastLogonDate,WhenChanged,@{Name="Account Status"; Expr={iid $_.userAccountControl}}  | Export-Csv c:\shell\reports\UserReport.csv -Append
0
Comment
Question by:clickbank
[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
  • 3
  • 3
7 Comments
 
LVL 57

Expert Comment

by:Mike Kline
ID: 39631841
I used the method that Jaap used here    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/17daaf37-5001-4075-b073-2633bcf7dc60/powershell-how-to-append-datetime-to-csv-export?forum=ITCG

The only thing I did different was not use the hh-mm-ss.   I used

$CurrentDate= $CurrentDate.ToStrong('MM-dd-yyyy')

Thanks

Mike
0
 

Author Comment

by:clickbank
ID: 39631871
Hi Mike,
thanks for getting back with me.  I looked at that link and added it but it but the date and time in the name of the file not it the report as I need it. do you know how it would be added in the report?  I have tried get-date but that is all I ge the date and not the other information that I pulled.

thanks
CB
0
 
LVL 57

Expert Comment

by:Mike Kline
ID: 39631881
ok so you want a column in the csv with the date?
0
Industry Leaders: 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!

 

Author Comment

by:clickbank
ID: 39631898
yes sorry if I did not expain clearly.
0
 
LVL 57

Expert Comment

by:Mike Kline
ID: 39631908
In the select-object portion you can add the $currentdate variable that you just used
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39632600
Try to create a Custom property..
Get-ADUser -Filter * -SearchBase "OU=**,DC=***,DC=***,DC=***" -Properties CN,LastLogonDate,WhenChanged,userAccountControl | Select-Object CN,LastLogonDate,WhenChanged,@{Name="Account Status"; Expr={iid $_.userAccountControl}},@{N="Date"; E={Get-Date -Format d}}  | Export-Csv c:\shell\reports\UserReport.csv -Append

Open in new window

0
 

Author Closing Comment

by:clickbank
ID: 39633428
This worked perfect! Thank you for the helping hand.
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

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...
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
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…

726 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