Solved

Add Date/Time to powershell exported results filename?

Posted on 2014-04-17
6
12,443 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
[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
  • 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
Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

 
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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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