?
Solved

add date to cvs report in Powershell

Posted on 2013-11-07
7
Medium Priority
?
780 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
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!

 

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 2000 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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

777 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