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

x
?
Solved

PowerShell Output to CSV by Date and Rename

Posted on 2013-12-23
3
Medium Priority
?
764 Views
Last Modified: 2013-12-23
I have a powershell script that gets Exchange calendar permissions and saves it to csv.  I'm working on creating an automated report that will email the changes in permissions on a daily basis.  One of the components I need assistance with is having the output saved to include the date in the file name in the form of YYYYMMDDcalpermissions.csv

Presently the script saves it as a static name, but when I run an automated daily comparison, I need a way to differentiate between yesterday's export and today.

How do I change the output to be named on variable based on the computer's date?

$Output | Sort-Object Mailbox | Select-Object Mailbox, User, {$_.AccessRights}, IsValid | Export-Csv -Path C:\CalendarPermissions.csv -NoTypeInformation

Thank you.
0
Comment
Question by:fireguy1125
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 total points
ID: 39736818
Try..
$Output | Sort-Object Mailbox | Select-Object Mailbox, User, {$_.AccessRights}, IsValid | Export-Csv -Path "C:\$(Get-Date -F yyyyMMdd)-CalendarPermissions.csv" -NoTypeInformation

Open in new window

0
 
LVL 41

Expert Comment

by:footech
ID: 39736822
$outfile = "c:\$(get-date -f yyyyMMdd)calpermissions.csv"

Open in new window

then substitute the variable for the path parameter
Export-Csv -Path $outfile -NoTypeInformation

Open in new window

0
 
LVL 41

Expert Comment

by:footech
ID: 39736829
Looks like Subsun beat me to it...  :)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

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 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.
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ā€¦
Screencast - Getting to Know the Pipeline

963 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