Solved

Variable in Compare Object input in Powershell

Posted on 2013-12-23
4
422 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now