<< Back to Script Library

Show AD user and manager details

This script displays a user’s Name, Company, Title, Office, Office Phone Number, Mobile Phone Number and E-Mail Address if they exist in AD, as well as those same details for their Manager.

Requires the ActiveDirectory PowerShell module loaded on machine this is be exected from.

Created by Rory Monaghan.
Version: 1.1.7
Created: 2018-11-26
Modified: 2018-11-27
Creator: Rory.Monaghan
Downloads: 146
Tags: Active Directory User Details
The Script Copy Script Copied to clipboard
<#

.DESCRIPTION
    
     This script displays a users Name, Company, Title, Office, Office Phone Number, Mobile Phone Number
     and E-Mail Address, as well as those same details for their Manager. Created by Rory Monaghan. 

.PARAMETER User
    
     Specifies an Active Directory user object provided through a ControlUp Argument

#>

$user=$args[0].split("\")[1]
write-host $user

$ErrorActionPreference = "Stop"

If ( (Get-Module -Name ActiveDirectory -ErrorAction SilentlyContinue) -eq $null )
{
    Try {
        Import-Module ActiveDirectory
    } Catch {
        Write-Error "Unable to load the module" -ErrorAction Continue
        Write-Error $Error[1] -ErrorAction Continue
        Exit 1
    }
}

Try {
    $managerfirstname=(get-aduser (get-aduser $user -Properties manager).manager).GivenName
    $managerlastname=(get-aduser (get-aduser $user -Properties manager).manager).SurName
    $manageraccname=(get-aduser (get-aduser $user -Properties manager).manager).samaccountName

    Get-AdUser -Identity $user -Properties * | Select GivenName,Surname,Department,Title,Company,mail,telephoneNumber,MobilePhone,Office
    write-host "Reporing Manager is $managerfirstname $managerlastname : "
    Get-AdUser -Identity $manageraccname -Properties * | Select GivenName,Surname,Department,Title,Company,mail,telephoneNumber,MobilePhone,Office

} Catch {
    Write-Error $Error[0] -ErrorAction Continue
    Exit 1
}