Show AD user and manager details

Version: 1.1.7
Creator Name: Rory.Monaghan
Date Created: 2018-11-26
Date Modified: 2018-11-27
Scripting language: PS
Download Count: 128

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.
Tags: Active Directory,User Details

The Script

<#

.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
}