Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Matching variables and Compare-Object

Avatar of SingAbout Martin
SingAbout Martin asked on
ExchangeActive DirectoryPowershell
24 Comments1 Solution169 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
Avatar of Chris Dent
Chris DentFlag of United Kingdom of Great Britain and Northern Ireland imagePowerShell Developer
Commented:
This problem has been solved!
Unlock 1 Answer and 24 Comments.
See Answers