Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Variable in Compare Object input in Powershell

Posted on 2013-12-23
4
Medium Priority
?
432 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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