Solved

PowerShell Output to CSV by Date and Rename

Posted on 2013-12-23
3
744 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 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

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.

Question has a verified solution.

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

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
A procedure for exporting installed hotfix details of remote computers using powershell
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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ā€¦

679 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