#powershell Script: Find Active Directory User I

Find-AdUserI is one of the many PowerShell functions/utilities in my personal script toolbox repository designed to help simplify the management and administration of just about any Active Directory Directory Services (AD DS) environments.

This self-explanatory utility works in PowerShell v2.0 and higher without any dependency on the AD PowerShell Module or other third party modules. It accepts SamAccountName as a parameter; you can customize the search criteria to displayname or any supported AD user attributes for example. You don’t even need to know or specify the domain name if your AD environment is a straightforward single forest single domain setup. Enjoy!

################################################################################
# Copyright (c) 201x-2017 leedesmond.com
# All Rights Reserved. Use at your own risk and responsibility.
# Find-AdUserI.ps1
# Version 1.00
#
# USAGE:
# Find-AdUserI desmond
#
# OUTPUT:
# All AD properties of the user.
#
################################################################################
function Find-AdUserI
{
param([string]$samaccountname)

$root = [ADSI]””;
$searcher = New-Object System.DirectoryServices.DirectorySearcher($root);
$searcher.pagesize = 1000;
$searcher.filter = “(&(objectClass=user)(samaccountname=$samaccountname))”;
$user = $searcher.findall(); #findone()
$user = % { $_.Properties }
Write-Output $user;
} #Find-AdUserI()

Bookmark the permalink.

Leave a Reply