Public/Get-Team.ps1
Function Get-Team { [CmdletBinding()] param ( [Parameter( ValueFromPipelineByPropertyName )] $Manager, [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 { if ($null -ne $Manager) { Write-Verbose "Searching based on ($Manager)" $Users = Get-ADUser -Filter "manager -eq '$Manager'" -Properties $Properties | Select-Object $Select Return $Users } elseif ($Identity) { $Users = @() foreach ($SearchTerm in $Identity) { $Manager = (Get-ADUser -Filter "employeeid -eq '$SearchTerm' -or SamAccountName -eq '$SearchTerm' -or DistinguishedName -eq '$SearchTerm' -or GUID -eq '$SearchTerm' -or SID -eq '$SearchTerm' -or EmployeeID -eq '$SearchTerm' -or mail -eq '$SearchTerm' -or UserPrincipalName -eq '$SearchTerm'" -Properties Manager).Manager $Users += Get-ADUser -Filter "manager -eq '$Manager'" -Properties $Properties | Select-Object $Select } Return $Users } else { Write-Warning "No Search Info Provided" } } END {} } |