Solved

Powershell - Compare two variables

Posted on 2016-12-01
1
76 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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