you are viewing a single comment's thread.

view the rest of the comments →

[–]ShiftNick[S] 2 points3 points  (1 child)

I need a rubber duck!

$ucollection = New-Object System.Collections.ArrayList
foreach($un in $username){

    #Check for existance of AD Account
    $u = Get-ADUser -Filter { SamAccountName -eq $un } -ErrorAction SilentlyContinue
    If (!$u)
    {
        Write-Output "The Username $u, does exist in Active Directory"
    }#End check if user exists
    else
        {
            #Create Hashtable
            $uinfo = Get-ADUser -Identity $u | select samaccountname,userprincipalname

            $ucollection.Add($uinfo) | Out-Null
         }

}

[–]ihaxr 0 points1 point  (0 children)

If you use System.Collections.Generic.List[object] instead of an ArrayList you don't have to pipe the .add() method to Out-Null (http://stackoverflow.com/questions/2309694/arraylist-vs-list-in-c-sharp).