Solved

PowerShell Output to CSV by Date and Rename

Posted on 2013-12-23
3
747 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
[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
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 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 40

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 40

Expert Comment

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

Featured Post

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…

738 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