Hi mates,
how many times you asked to yourself : how can I compare file contents ?
I had some needs during the previous days....I know you too, maybe :-)
Anyway my last one was related to a complex script that should evaluate the password change of active directory users : if the user didn't change the password during the last 90 days we send him a first email. The week later another time : if the user of the first week didn't change the password yet we send him a second email, different from the first one, informing him that the week later we will disable his account. The last week another time : if the user is still persisting we lock the account.
The logic behind this script is complex enough, at least for me....I'm not a programmer.
I needed to compare several text files reporting the result of the queries done during the three weeks examined before.
I'll post this script later, during next weeks but in the meantime I would like to share some brief consideration regarding the file comparison.
So first of all I need to compare two text files and extract ONLY EQUAL items.
So text file 1 has :
a
b
c
d
Text file 2 has :
d
e
f
g
So logically speaking the result should be "d".
Here below the code :
In a separate situation but always inside the same script I needed to take only object that were different on the first and , separately, on the second file.
DIFFERENT, I repeat.
Here below the code (same file, same content....only for one direction):
....add (at the end of the "compare-object" line")
| select-object -expand inputobject
if you want to have only the result without the column labels.
For the sake of the article.....the normal behavior of compare object is the following
The arrow direction indicate where the object is "univocally" present (file 1 or file 2).
No complications, no tricks, only the essential.
Hope this helps.
See you soon
No comments:
Post a Comment