Solved

Add Date/Time to powershell exported results filename?

Posted on 2014-04-17
6
9,158 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 28

Expert Comment

by:becraig
Comment Utility
I guess this could work

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

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

Open in new window

0
 
LVL 28

Expert Comment

by:becraig
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 28

Expert Comment

by:becraig
Comment Utility
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 28

Accepted Solution

by:
becraig earned 500 total points
Comment Utility
$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
Comment Utility
Thanks BeCraig!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now