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

x
?
Solved

add date to cvs report in Powershell

Posted on 2013-11-07
7
Medium Priority
?
802 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

604 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