Solved

Powershell - Compare two variables

Posted on 2016-12-01
1
93 Views
Last Modified: 2016-12-01
Hi,

I have to two variables. The first one contains computernames (ex. COMP01, COMP02, COMP03) and the second one also contains computernames, but with some extra fillings (ex. INFO_COMP01.txt, INFO_COMP02.txt, INFO_COMP03.txt).

Is it possible to compare these two variables and find those missing in one of the variables?

I'll use this for cleaning up, when a computer is deleted manually in AD.
0
Comment
Question by:Sum Wum
1 Comment
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41908298
Certainly.
Used this for testing:
$ComputerList = 'COMP01', 'COMP02', 'COMP03'
$FileList = 'INFO_COMP01.txt', 'INFO_COMP03.txt', 'INFO_COMP04.txt'

Open in new window

And this provides the results:
Compare-Object -ReferenceObject $ComputerList -DifferenceObject ($FileList | % {$_.Split('_.')[1]})

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
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…

713 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