0

I would like to compare two organizational units users. I can get my user list with this command:

OU_NUMBER_1:

Get-ADUser -filter * -SearchBase "OU=OU_NUMBER_1,OU=OU-SNE_SharePoint,DC=vf,DC=local" | Select sAMAccountName


OU_NUMBER_2:
    Get-ADUser -filter * -SearchBase "OU=OU_NUMBER_2,OU=OU-SNE_SharePoint,DC=vf,DC=local" | Select sAMAccountName

I would like to get homonymous from these lists. Do I have to put my users in some lists and compare them ? Or anyone get a better idea ?

To summary, I would like to get a list with homonymous of my OU's.

Kara
  • 6,115
  • 16
  • 50
  • 57
Sam
  • 11
  • 4

2 Answers2

0

/Update

Try

$UserGroup1 = Get-ADUser -filter * -SearchBase "OU=OU_NUMBER_1,OU=OU-SNE_SharePoint,DC=vf,DC=local" | select sAMAccountName


$UserGroup2 = Get-ADUser -filter * -SearchBase "OU=OU_NUMBER_2,OU=OU-SNE_SharePoint,DC=vf,DC=local" | Select sAMAccountName


$UserInBothOU = Compare-Object $UserGroup1 $UserGroup2 -IncludeEqual

Be aware that the Array $UserInBothOU contains PowerShell Objects. When you want the sAMAccountName, then you must do something like that:

foreach($User in $UserInBothOU)
{
    Write-host $User.sAMAccountName
}

Because sAMAccountName is only an attribute.

Solaflex
  • 1,382
  • 1
  • 13
  • 24
  • I have tested your solution. But I can't get any user in my $UserInBothGroups Even if I change my PS code with this, nothing is contained in it: Foreach($User in $UserGroup1) { [Array]$UserInBothGroups += $User } – Sam May 02 '13 at 15:20
  • Please try out my update. If this even doesn't work, you have to wait until tomorrow, when I am at work :) – Solaflex May 02 '13 at 18:06
  • Thank you ! I'll test tomorrow at work too and I'll keep you in touch ! ;) – Sam May 02 '13 at 18:50
0
$OLDGroup = Get-ADUser -filter * -SearchBase "OU=InactiveObjects,DC=gov,DC=au" -server "gov.au" | select sAMAccountName

$NEWGroup = Get-ADUser -filter * -SearchBase "OU=StandardUsers,OU=Users,DC=nsw,DC=gov,DC=au" -server "nsw.gov.au" | Select sAMAccountName

compare-object $OLDGroup $NEWGroup -Property 'SamAccountName' -IncludeEqual
Derrick
  • 3,669
  • 5
  • 35
  • 50
Dave
  • 1