Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell - Compare two variables

Posted on 2016-12-01
1
Medium Priority
?
326 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 2000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
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…

610 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