Solved

Powershell - Compare two variables

Posted on 2016-12-01
1
167 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
[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
1 Comment
 
LVL 85

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 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