Get-ADUserBasicInfo


Formatting Basic AD Information in the Output your Want

Get-ADUserBasicInfo Function

by Michael J. Thomas

Here is an example of how you an put together a basic list of information that you want to find out about a user's account.




<#
.Synopsis
   Get-ADUserBasicInfo
.DESCRIPTION
   Gets the basic information of the user. Including UserName, First Name, Last Name, Email Address,
   O365,Exchange DB, Title, Enabled, LockedOut, LastLogonDate, User OU, Notes

.EXAMPLE
   Get-ADUserBasicInfo -UserName "PowerShellGuy"
.EXAMPLE
    Get-ADUserBasicInfo -UserName "PowerShellGuy","michael.thomas"
#>
function Get-ADUserBasicInfo{
 [cmdletbinding()]
 Param(
 [string[]]$UserName
  )
  #$ErrorActionPreference= 'silentlycontinue'
 Foreach ($User in $Username){


 $O365 = If ((Get-AdUser $User -Properties targetAddress).targetAddress -ne $null) {

If ((Get-ADUser $User -Properties targetAddress).targetAddress.Contains(".onmicrosoft.com")){
$true
}

}
Else{
$false

}
$LyncAccount = If ((get-aduser $User -Properties msRTCSIP-PrimaryHomeServer).'msRTCSIP-PrimaryHomeServer' -or `
(get-aduser $User -Properties msRTCSIP-DeploymentLocator).'msRTCSIP-DeploymentLocator'){
$true
}
Else{
$false
}
Get-ADUser -Identity $User -Properties SamAccountName, GivenName, SurName, EmailAddress, Title, Enabled, LockedOut, LastLogonDate, CanonicalName, homeMDB, Name, info, targetAddress | `
Select-Object @{name = 'UserName'; expression = {($_.SamAccountName.ToUpper())}}, `
@{Name = 'First Name'; Expression = {($_.GivenName)}}, `
@{Name = 'Last Name'; Expression = {($_.Surname)}}, `
@{Name = 'Email Address'; Expression = {($_.EmailAddress)}}, `
@{Name = 'O365'; Expression = {($O365)}},`
@{Name = 'Exchange DB'; Expression = { (($_.HomeMDB).split(',')[0]).split('=')[1] } }, `
@{Name = 'Lync Account'; Expression = {($LyncAccount)}},`
Title, Enabled, LockedOut, LastLogonDate, `
@{Name = 'User OU'; Expression = {($_.CanonicalName)}},
@{Name = 'Notes'; Expression = {($_.info)}}

}
}

Comments

Popular posts from this blog

Add-RemoteDesktopUsers

Invoke-Reprofile

Mike's Profile Cleanup Tool