Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add Date/Time to powershell exported results filename?

Posted on 2014-04-17
6
Medium Priority
?
15,769 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
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.

 
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

Introducing the WatchGuard 420 Access Point

WatchGuard's newest access point includes an 802.11ac Wave 2 chipset, providing the fastest speeds for VoIP, video and music streaming, and large data file transfers. Additionally, enjoy the benefits of strong security as the 3rd radio delivers dedicated WIPS protection!

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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.
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…
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…

688 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