Avatar of fireguy1125
fireguy1125
 asked on

PowerShell Output to CSV by Date and Rename

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.
Powershell

Avatar of undefined
Last Comment
footech

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
SubSun

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
footech

$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

footech

Looks like Subsun beat me to it...  :)
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes