Solved

add date to cvs report in Powershell

Posted on 2013-11-07
7
720 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
  • 3
  • 3
7 Comments
 
LVL 57

Expert Comment

by:Mike Kline
Comment Utility
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
Comment Utility
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
Comment Utility
ok so you want a column in the csv with the date?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:clickbank
Comment Utility
yes sorry if I did not expain clearly.
0
 
LVL 57

Expert Comment

by:Mike Kline
Comment Utility
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
Comment Utility
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
Comment Utility
This worked perfect! Thank you for the helping hand.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
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 …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now