Public/Find-MDSUserName.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
function Find-MDSUserName { <# .SYNOPSIS Retrieve users' account usernames based on full or partial name search. .Parameter NameValue The full or partial name of the user or users. .Parameter FilterAttribute Specify a single attribute to query. Default value uses Ambiguous Name Resolution (ANR) which searches up to 17 name related attributes in Active Directory. .DESCRIPTION The Get-MDSUserName function uses the Get-ADUser cmdlet to query Active Directory for all users .EXAMPLE Find-MDSUserName Smith .EXAMPLE Find-MDSUserName Smi .EXAMPLE Find-MDSUserName -GivenName John .EXAMPLE Find-MDSUserName -GivenName Jo .EXAMPLE Find-MDSUserName John -FilterAttribute Surname .EXAMPLE Find-MDSUserName John,Smith -FilterAttribute Surname .EXAMPLE Find-MDSUserName 12345 -FilterAttribute EmployeeID #> #requires -Module ActiveDirectory Param( [parameter(Mandatory=$true)] [string[]]$NameValue, [parameter(Mandatory=$false)] [string]$FilterAttribute='ANR' ) Begin {} Process { ForEach ($User in $NameValue) { # Get SAM Account Name for specified user Get-ADUser -Filter "$FilterAttribute -like '$User*'" | Select-Object GivenName,SurName,SamAccountName,UserPrincipalName } } End {} } # End Find-MDSUserName |