Solved

Variable in Compare Object input in Powershell

Posted on 2013-12-23
4
426 Views
Last Modified: 2013-12-23
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,'$_.AccessRights',IsValid |

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!
0
Comment
Question by:fireguy1125
  • 2
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39736833
For today's date..
"$(get-date -f yyyyMMdd)calpermissions.csv"

Open in new window

For yesterday's date..
"$("{0:yyyyMMdd}" -f (get-date).AddDays(-1))calpermissions.csv"

Open in new window

0
 
LVL 1

Author Comment

by:fireguy1125
ID: 39736846
Would this be the proper format for my script?

compare-object (import-csv "$(get-date -f yyyyMMdd)calpermissions.csv" | sort) (import-csv "$("{0:yyyyMMdd}" -f (get-date).AddDays(-1))calpermissions.csv" | sort) -passthru -property Mailbox,User,'$_.AccessRights',IsValid |
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39736853
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.csv"
0
 
LVL 1

Author Closing Comment

by:fireguy1125
ID: 39736855
Tested works great! Thanks!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 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