Compare-Object Pass Into Get-ADUser To Get DisplayName

389 Views Asked by At

Good day. What I am trying to accomplish is showing the DisplayName as well as the Name but the only thing I can get to show with Compare-Object is Name so I am trying to pass the output from Compare-Object into Get-ADUser to get more user information. Below is the code that I am working with.

Import-Module ActiveDirectory #imports AD module
$group = Read-Host "What is the group name that you want to get membership for?"
$list = Get-ADGroupMember $group -recursive | Select Name

$OU = Read-Host "What is the OU that you want a list of? [List full path {OU=xxx,DC=xxx,DC=xxx}]"
$OUList = Get-ADUser -SearchBase $OU -Filter * -Properties Name, DisplayName, Title | Select Name

$Comparison = (Compare-Object -ReferenceObject $list -DifferenceObject $OUList | Where-Object {$_.SideIndicator -eq "=>"} | Select Name
ForEach ($user in $Comparison) {Get-ADUser $user.InputObject -Properties Name,DisplayName | Select Name, DisplayName}

The error I get is

Get-ADUser : Cannot bind parameter 'Identity'. Cannot convert value "@{Name=username}" to type Microsoft.ActiveDirectory.Management.ADUser

I know this is probably something simple but I can't quite figure it out. Thank you for any assistance.

0

There are 0 best solutions below