fireguy1125
asked on
Variable in Compare Object input in Powershell
Please excuse my terminology as I'm a powershell/scripting novice, however I have a script developed that compares two csv files and provides differences between them in an output csv file. I have another script that is used to execute the exchange powershell query to gather the date. I have another question open on how to get those results in a date variable. I would need to know how I can have the compare script, which I have included a piece of below, change the compare-objects each day it runs.
The data gather script is set to run once per day, dumping the results in the same folder location as this script. I want to change the Export.csv and Exportold.csv to varibles based on date, so every time the script runs, it will change the variable of each of htese properties to one name being the current date, and comparing it to yesterday's date.
For example:
export.csv would be 20131223calpermissions.csv
exportold.csv would be 20131222calpermissions.csv
And this would automatically change each day, without having to modify the script.
compare-object (import-csv Export.CSV | sort) (import-csv Exportold.CSV | sort) -passthru -property Mailbox,User,'$_.AccessRig hts',IsVal id |
If there is a better way of doing this, i'm open to suggestions, and again I'm a script novice so bear with me. Thank you in advance!
The data gather script is set to run once per day, dumping the results in the same folder location as this script. I want to change the Export.csv and Exportold.csv to varibles based on date, so every time the script runs, it will change the variable of each of htese properties to one name being the current date, and comparing it to yesterday's date.
For example:
export.csv would be 20131223calpermissions.csv
exportold.csv would be 20131222calpermissions.csv
And this would automatically change each day, without having to modify the script.
compare-object (import-csv Export.CSV | sort) (import-csv Exportold.CSV | sort) -passthru -property Mailbox,User,'$_.AccessRig
If there is a better way of doing this, i'm open to suggestions, and again I'm a script novice so bear with me. Thank you in advance!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Yes it should work if you are running the code from the folder where the file exist.. Else you need to add the path...
For example..
import-csv "C:\temp\$(get-date -f yyyyMMdd)calpermissions.cs v"
For example..
import-csv "C:\temp\$(get-date -f yyyyMMdd)calpermissions.cs
ASKER
Tested works great! Thanks!
ASKER
compare-object (import-csv "$(get-date -f yyyyMMdd)calpermissions.cs