Solved

Variable in Compare Object input in Powershell

Posted on 2013-12-23
4
428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mailbox Delegation List 46 127
Powershell database 5 44
PowerShell script to get http response code 3 80
How do I convert from bytes to TB 4 29
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.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

739 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