troubleshooting Question

Matching variables and Compare-Object

Avatar of SingAbout Martin
SingAbout Martin asked on
PowershellExchangeActive Directory
24 Comments4 Solutions169 ViewsLast Modified:
I have the following situation to which I cannot find a solution, but I think it must be very easy. I have the following variables:

$DataA - This variable contains the "Name" of specific AD Users, as well as columns "LastLogon" and "WhenCreated".
$DataB - This variable contains the "DisplayName" of specific Exchange users as well as columns "LastLogonTime" and "LastLoggedOnUserAccount".
$DataC - This variable contains only the names of the users that are present in both $DataA and $DataB under the column name "InputObject" as a result of the Compare-Object command.

The variable $DataA and $DataB contain information that I want to see in the $DataC or a new variable. In $DataC I have a list of names, and I want the corresponding attributes from $DataA and $DataB combined to a new variable. So for example:

$DataC contains a column with name "InputObject" and a value of "Test User".
$DataA contains a column with name "Name" and a value of "Test User, AND a column with "LastLogon" and a value of 2017-04-03 02:26.
$DataB contains a column with name "DisplayName" and a value of "Test User, AND a column with "LastLogonTime" and a value of 2017-04-03 02:26.

In a new $DataD variable I want to have those combined. Alternatively, it would also be good if it is possible to select-objects from other variables within a Compare-Object command. That's because $DataC is generated through Compare-Object, but I cannot seem to add columns with information from $DataA or $DataB. Hopefully you can help.
ASKER CERTIFIED SOLUTION
Chris Dent
PowerShell Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2010

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 4 Answers and 24 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 24 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros