Resource Article

users report function

this psm1 function to generate user list to csv & pdf

Back to Resources
March 2026Powershell

Import-Module ActiveDirectory

 function GenReport()
{

param($members, $path, $reportname)
$count = 0
$outarray = @()

 foreach ($m in $members)

 {

  $count++

  $outarray += New-Object PsObject -property @{

        'Count' = $count.ToString()

        'Full Name' = $m.Name

        'Username' = $m.SamAccountName

        'LastLogon' =  $m.LastLogonDate

        }

  }

 

$outarray | Select-Object Count, "Full name", "Username", "LastLogon" | Export-Csv $path\$reportname.csv -NoTypeInformation

"Total # of users are $($members.Count)" | Add-Content  $path\$reportname.csv

$report = Import-Csv $path\$reportname.csv

$report | Out-PDFFile -Path $path\$reportname.pdf

}