Generate-ADOrgTreeInfoReport.ps1

  • 26 January 2024
  • Sean Huggans
Description: 

Outputs a CSV of AD user's relevant Org Tree Info.

Language: 
PowerShell
Usage Type: 
Standalone
Script Source: 
############################################
# Generate-ADOrgTreeInfoReport.ps1
# Author(s): Sean Huggans
$ScriptVersion = "24.1.26.1"
############################################
# Variables
#################################
$StandardUserOUDN = "OU=Standard Users,OU=SomeOU,DC=SomeSUbDomain,DC=Somewindowsdomain,DC=com"
 
############################################
# Execution Logic
#################################
$DateStamp = Get-Date -Format 'yyyyMMddHHmmss'
$StartLine = "DisplayName,LastName,FirstName,Description,Title,Department,Company,Manager"
Write-Host $StartLine
$StartLine | Out-File -FilePath "C:\Temp\OrgTreeInfoReport-$($DateStamp).csv" -Encoding utf8 -NoClobber -Force
foreach ($StandardUserAccount in $(Get-ADUser -Filter * -SearchBase $StandardUserOUDN -Properties * | Sort-Object -Property LastName)) {
    $ManagerDisplayName = "NO MANAGER SET"
    if ($StandardUserAccount.Manager) {
        $ManagerDisplayName = $(Get-ADUser -Identity $($StandardUserAccount.Manager) -Properties *).DisplayName
    }
    $OrganizationName = "NO ORGANIZATION SET"
    if ($StandardUserAccount.Company) {
        $OrganizationName = $StandardUserAccount.Company
    }
    $DepartmentName = "NO DEPARTMENT SET"
    if ($StandardUserAccount.Department) {
        $DepartmentName = $StandardUserAccount.Department
    }
    $TitleName = "NO DEPARTMENT SET"
    if ($StandardUserAccount.Department) {
        $TitleName = $StandardUserAccount.Title
    }
    $DescriptionText = "NO DESCRIPTION SET"
    if ($StandardUserAccount.Description) {
        $DescriptionText = $StandardUserAccount.Description
    }
    $UserLine = ""
    $UserLine = "$($StandardUserAccount.DisplayName),$($StandardUserAccount.Surname),$($StandardUserAccount.GivenName),$($DescriptionText),$($TitleName),$($DepartmentName),$($OrganizationName),$($ManagerDisplayName)"
    Write-Host $UserLine
    $UserLine | Out-File -FilePath "C:\Temp\OrgTreeInfoReport-$($DateStamp).csv" -Encoding utf8 -Force -NoClobber -Append
}
Note: that all applications posted here are posted for use, both commercial and non-commercial, free of charge, and as such are provided as-is, without warranty of any kind whatsoever. visuaFUSION, FMSCUG or any other program listed here's author are not responsible for any damages or shortcomings that result from usage of any of these applications.
Error | visuaFUSION Systems Solutions Blog

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /mnt/home/visuafus/public_html/bahusa.net/includes/common.inc:2861) in drupal_send_headers() (line 1551 of /mnt/home/visuafus/public_html/bahusa.net/includes/bootstrap.inc).
  • Error: Call to undefined function mail() in DefaultMailSystem->mail() (line 79 of /mnt/home/visuafus/public_html/bahusa.net/modules/system/system.mail.inc).

Error

The website encountered an unexpected error. Please try again later.