Solved

add date to cvs report in Powershell

Posted on 2013-11-07
7
766 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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
The viewer will learn how to dynamically set the form action using jQuery.
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)

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