Solved

PowerShell Output to CSV by Date and Rename

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

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 39

Expert Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

705 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

21 Experts available now in Live!

Get 1:1 Help Now