Public/Get-User.ps1
Function Get-User { <# .SYNOPSIS Provide a search value or user object to either find or expand into relevant data .NOTES Name: Get-User Author: Luke Hagar Version: 1.0 DateCreated: January 20th, 2021 .EXAMPLE Get-User -Search "Luke.Hagar" .EXAMPLE Get-User -DistinguishedName "CN=Luke Hagar (2187284),OU=Users,OU=CEN,OU=CE,OU=REGIONS,DC=wfm,DC=pvt" .EXAMPLE $UserObject | Get-User .LINK #> [CmdletBinding()] param ( [Parameter( ValueFromPipelineByPropertyName )] [Alias("employeeid", "mail")] $Search, [Parameter( ValueFromPipelineByPropertyName )] [Alias("SamAccountName")] $DistinguishedName = $ENV:USERNAME, [string[]]$Properties = @("Name", "EmployeeID", "physicalDeliveryOfficeName", "Title", "mail", "msRTCSIP-PrimaryUserAddress", "CanonicalName", "DistinguishedName", "samaccountname", "UserPrincipalname", "AccountExpirationDate", "Enabled", "Manager", "badPwdCount", "LastBadPasswordAttempt", "LockedOut", "LockOutTime", "lastLogonDate", "PasswordExpired", "PasswordLastSet", "whenCreated", "whenChanged"), [string[]]$Select = @("Name", "EmployeeID", "physicalDeliveryOfficeName", "Title", "mail", "msRTCSIP-PrimaryUserAddress", "CanonicalName", "DistinguishedName", "samaccountname", "UserPrincipalname", "AccountExpirationDate", "Enabled", "Manager", "badPwdCount", "LastBadPasswordAttempt", "LockedOut", "LockOutTime", "lastLogonDate", "PasswordExpired", "PasswordLastSet", "whenCreated", "whenChanged") ) BEGIN { } PROCESS { Write-Debug "Properties Requested: $Properties" Write-Debug "Properties Selected: $Select" if ($DistinguishedName) { Get-ADUser $DistinguishedName -Properties $Properties | Select-Object $Select } elseif ($Search) { Foreach ($SearchValue in $Search) { Get-ADUser -Filter "employeeid -eq $SearchValue -or mail -eq '$SearchValue'" -Properties $Properties | Select-Object $Select } } } END { } } |