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("SamAccountName", "DistinguishedName", "GUID", "SID", "EmployeeID", "mail", "UserPrincipalName")] $Identity = $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" Foreach ($SearchValue in $Identity) { Get-ADUser -Filter "employeeid -eq '$SearchValue' -or SamAccountName -eq '$SearchValue' -or DistinguishedName -eq '$SearchValue' -or GUID -eq '$SearchValue' -or SID -eq '$SearchValue' -or EmployeeID -eq '$SearchValue' -or mail -eq '$SearchValue' -or UserPrincipalName -eq '$SearchValue'" -Properties $Properties | Select-Object $Select } } END { } } |