Solved

Powershell - Compare two variables

Posted on 2016-12-01
1
7 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 82

Accepted Solution

by:
oBdA earned 500 total points
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

11 Experts available now in Live!

Get 1:1 Help Now