On Tue, Mar 5, 2013 at 11:39 AM, Michael B. Smith <[email protected]> wrote:
> Ok, small enough to do a brute force search.

Yeah, I did something pretty much similar:

$AllCSVUsers = @(Import-CSV $InputFileName) | Sort
$TotCntCSVUsers = $AllCSVUsers.count

$All_AD_Users = Get-QADUser -Enabled -SizeLimit 0 -LastName * | Select
givenName,LastName,DisplayName,description,mail,DN,SAMAccountName,homeDirectory
| Sort LastName,givenName

$TotCntMatched = 0
$TotCntNotMatched = 0


ForEach ($AD_User in $All_AD_Users)
{
  $IndexValue = 0
  ForEach ($CSVUser in $AllCSVUsers)
    {
    $IndexValue++
    IF (($AD_User.LastName -eq $CSVUser.LastName) -and
($AD_User.FirstName -eq $CSVUser.FirstName))
        {
          $TotCntMatched++
          Break
        }
    }
    IF ($IndexValue -eq $TotCntJennyUsers)
        {
        $TotCntNotMatched++
        $TotCntNotMatchedStr = "#{0,4}:" -f $TotCntNotMatched
        Write-Host "RATZ! " $TotCntNotMatchedStr "Could not find AD
user:" $AD_LastName $AD_FirstName " (" $AD_User.DisplayName ")"


>
> In pseudo-code (I don't use QAD and I didn't test it)
>
>         $AllCSVUsers = @(Import-CSV $InputFileName)
>         $TotCntCSVUsers =  $AllCSVUsers.count
>
>         foreach( $row in $AllCSVUsers )
>         {
>                 $user = Get-AdUser -Filter { ( GivenName -eq $row.FirstName ) 
> -and ( Surname -eq $row.LastName ) } -SearchBase "dc=contoso,dc=local" 
> -SearchScope Subtree
>                 if( $user )
>                 {
>                         ### you found a record for matching firstname and 
> lastname
>                 }
>                 else
>                 {
>                         ### no such record
>                 }
>         }
>
> -----Original Message-----
> From: Michael Leone [mailto:[email protected]]
> Sent: Tuesday, March 5, 2013 11:15 AM
> To: NT System Admin Issues
> Subject: Re: Powershell advice - matching an AD user to a value in an array
>
> On Tue, Mar 5, 2013 at 11:05 AM, Michael B. Smith <[email protected]> 
> wrote:
>> How many users do you have? How many users are in the CSV file?
>>
>> Approximate, in both cases, is fine.
>
> CSV users = 1300. AD users = <1100.
>
> What I am most interested in: AD users NOT in CSV file. There will always be 
> users in CSV file not in AD; that is fine. What I need to know is - who is in 
> AD that isn't accounted for, in the CSV file.
>
>>
>> -----Original Message-----
>> From: Michael Leone [mailto:[email protected]]
>> Sent: Tuesday, March 5, 2013 10:54 AM
>> To: NT System Admin Issues
>> Subject: Powershell advice - matching an AD user to a value in an
>> array
>>
>> So I have this CSV file of names (LastName, FirstName). What I need to
>> do: find every AD user that is in that CSV file. If they are not there, 
>> report that, too.
>>
>> So I imported the whole CSV into an array, and use Quest to get all active 
>> user objects:
>>
>> $AllCSVUsers = @(Import-CSV $InputFileName) $TotCntCSVUsers =
>> $AllCSVUsers.count
>>
>> $AllUsers = Get-QADUser -SizeLimit 0 | Select
>> LastName,givenName,DisplayName
>>
>> But I am unclear on how to (easily) search each AD user against the CSV 
>> array.
>>
>> ForEach ($AD_User in $AllUsers)
>> {
>> $LastName=$AD_User.LastName
>> $FirstName=$AD_User.FirstName
>>
>> - then what? Do loop thru the CSVUsers array, looking for both $LastName and 
>> $FirstName? Can Compare-Object help me here?
>>
>> I foresee problems, especially if the names don't match exactly, or I have 
>> multiple John Does. But all I have is that CSV file.
>>
>> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~
>> <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>>
>> ---
>> To manage subscriptions click here:
>> http://lyris.sunbelt-software.com/read/my_forums/
>> or send an email to [email protected]
>> with the body: unsubscribe ntsysadmin
>>
>> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~
>> <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>>
>> ---
>> To manage subscriptions click here:
>> http://lyris.sunbelt-software.com/read/my_forums/
>> or send an email to [email protected]
>> with the body: unsubscribe ntsysadmin
>>
>
> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ 
> <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>
> ---
> To manage subscriptions click here: 
> http://lyris.sunbelt-software.com/read/my_forums/
> or send an email to [email protected]
> with the body: unsubscribe ntsysadmin
>
> ~ Finally, powerful endpoint security that ISN'T a resource hog! ~
> ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~
>
> ---
> To manage subscriptions click here: 
> http://lyris.sunbelt-software.com/read/my_forums/
> or send an email to [email protected]
> with the body: unsubscribe ntsysadmin
>

~ Finally, powerful endpoint security that ISN'T a resource hog! ~
~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/>  ~

---
To manage subscriptions click here: 
http://lyris.sunbelt-software.com/read/my_forums/
or send an email to [email protected]
with the body: unsubscribe ntsysadmin

Reply via email to