Solved

Add Date/Time to powershell exported results filename?

Posted on 2014-04-17
6
11,090 Views
Last Modified: 2014-04-17
We have a Powershell Script that exports/saves a report locally.

Is there a way to make the report add the date/time it was run  into the actual file name?
0
Comment
Question by:GCTTechs
  • 4
  • 2
6 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40006934
I guess this could work

$timer = (Get-Date) -replace "/", "-" `
-replace " ","" `
-replace ":", ""

$filename = "c:\" + $timer + "file.txt"

Open in new window

0
 
LVL 29

Expert Comment

by:becraig
ID: 40006991
This is also shorter and easier:


$timer = (Get-Date -Format yyy-mm-dd-hhmm)
$filename = "c:\" + $timer + "file.txt"

Open in new window


If you show how the filename is being created I can just plug it in.
0
 

Author Comment

by:GCTTechs
ID: 40007006
I'm actually trying to edit this PS1 file so that I can run it daily and keep a separate copy, showing the date/time in the filename.

http://gallery.technet.microsoft.com/office/Generate-Exchange-2388e7c9 
http://www.stevieg.org/2011/06/exchange-environment-report/

Its Steve Goodman's Exchange Environment Report.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 29

Expert Comment

by:becraig
ID: 40007019
If it is the first one:
$timer = (Get-Date -Format yyy-mm-dd-hhmm)
$filename = "c:\" + $timer + "report.html"
.\Get-ExchangeEnvironmentReport -HTMLReport $filename

Open in new window

0
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 40007024
$timer = (Get-Date -Format yyy-mm-dd-hhmm)
$filename = "c:\" + $timer + "report.html"
.\Get-ExchangeEnvironmentReport -HTMLReport $filename -SendMail:$true -MailFrom:you@example.com -MailTo:you@example.com -MailServer:smtp.example.com

Open in new window


$timer = (Get-Date -Format yyy-mm-dd-hhmm)
$filename = "c:\" + $timer + "report.html"
.\Get-ExchangeEnvironmentReport -HTMLReport $filename -SendMail:$true -MailFrom:you@example.com -MailTo:you@example.com -MailServer:smtp.example.com -ScheduleAs:DOMAIN\user

Open in new window

0
 

Author Comment

by:GCTTechs
ID: 40007068
Thanks BeCraig!
0

Featured Post

Are your AD admin tools letting you down?

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

825 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