Script Repository

Export user properties to CSV file

May 20, 2021

The script exports specified properties of the target user to a CSV file and sends the file via email. To execute the script, create a scheduled task, a custom command or a business rule configured for the User object type.


  • $csvFilePath - Specifies the path to the CSV file to be created.
  • $removeCsvFile - Specifies whether the CSV file will be removed after sending the email notification.
  • $propertiesToExport - Specifies the LDAP names of the properties whose values will be present in the CSV file.
  • $to - Specifies the recipient email address.
  • $subject - Specifies the email notification subject.
  • $from - Specifies the email address from which the email notification will be sent.
  • $mailServer - Specifies the FQDN of the mail server that will be used to deliver the email notification.
  • $body - Specifies the email notification body.
Edit Remove
$csvFilePath = "C:\Scripts\Report.csv" # TODO: modify me
$removeCsvFile = $True # TODO: modify me
$propertiesToExport = @("givenName", "middleName", "sn", "title", "co", "mail") # TODO: modify me

# Email message settings
$to = "" # TODO: modify me
$subject = "Properties of user %fullname%" # TODO: modify me
$from = "" # TODO: Modify me
$mailServer = "" # TODO: Modify me
$body = "Properties of user %fullname%" # TODO: Modify me

$propertyNameToValue = @{}
foreach ($propertyName in $propertiesToExport)
        $value = $Context.TargetObject.Get($propertyName)
        $value = $NULL
    $propertyNameToValue.Add($propertyName, $value)

$record = New-Object PSObject -Property $propertyNameToValue
@($record) | Export-Csv -Path $csvFilePath -NoTypeInformation

# Send mail
Send-MailMessage -to $to -From $from -Subject $subject -Body $body -SmtpServer $mailServer -Attachments $csvFilePath

if ($removeCsvFile)
    # Remove CSV File
    Remove-Item $csvFilePath -Force

Comments ( 0 )
No results found.
Leave a comment