Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Add Date/Time to powershell exported results filename?

Posted on 2014-04-17
6
Medium Priority
?
17,200 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…
Loops Section Overview

773 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