Public/Invoke-GetADUser.ps1
function Invoke-GetADUser { <# .SYNOPSIS Gets information about an Active Directory user .PARAMETER UserName Target user .EXAMPLE !User dk.test.hz #> [PoshBot.BotCommand( CommandName = 'user', Aliases = ('ADUser', 'who', 'search') )] [cmdletbinding()] param( [parameter(Mandatory)] [string]$username ) Import-Module ActiveDirectory $searchname = '*' + $username + '*' $GCADUser = Get-ADUser -Filter { (((SamAccountName -like $searchname) -or (Name -like $searchname)) -and ((Enabled -eq $true) -and (mail -like "*"))) } -Server sundc1:3268 -Properties * $childdomain = ($GCADUser.DistinguishedName -split '(DC=)' | Select-Object -index 2).replace(',', '') $dc = (Get-ADDomainController -Discover -DomainName $childdomain).Name $ADPrincipalGroupMembership = Get-ADPrincipalGroupMembership -identity $GCADUser.SamAccountName -server $dc New-PoshBotCardResponse -Text ($GCADUser | Select-Object Name, UserPrincipalName, mail, telephonenumber, mobile, department | Out-String) -Title "Contact Info" New-PoshBotCardResponse -Text ($ADPrincipalGroupMembership | Select-Object name, GroupCategory, GroupScope, distinguishedName | Out-String) -Title "Group Memberships" } |