Thanks for the reply. I guess I needed to explain my scenario a little better. I'm unable to use $context because the export isn't running on just a "user" object. I have a "handle" on the user because it was retrieved as part of a search. I'm looping through the search results and exporting attributes from each user. I'll attach a snippet of the code so you get a better idea of what I'm doing.
try
{
$userResult = $userSearcher.ExecuteSearch()
$sortedUsers = $userResult.FetchAll()
$totalUserCount = $sortedUsers.Count
$Context.LogMessage("The number of users is: " + $totalUserCount, "Information")
$count = 0
# Get the user information from the search results, convert to JSON and add them to the file
# Write out opening bracket
Add-Content $exportFile "["
foreach ($user in $sortedUsers)
{
$hash1 = @{}
for ($i=0; $i -lt $eachFieldIn.length; $i++)
{
if ($eachFieldIn[$i] = "positionPrimarySupervisor")
{
# Get the Primary Supervisor's name
$managerLU = $user.Properties[$eachFieldIn[$i]].Value
$manager = $Context.BindToObject($managerLU.AdsPath)
$managerDN = New-Object "Softerra.Adaxes.Ldap.DN" $manager.Get("distinguishedName")
$parentDisplayName = GetObjectDisplayName($managerDN.Parent.ToString())
if ($managerDN -ne $NULL) {
$fldValue = $parentDisplayName
} else {
$fldValue = ""
}
} else {
$fldValue = $user.Properties[$eachFieldIn[$i]].Value
}
# Add key/value pair to hash table
$hash1.Add($eachFieldOut[$i] , $fldValue)
$result = ConvertTo-Json20($hash1)
$count++
# If it's not the last record, add a comma to the end of the content, otherwise, leave it off
if ($count -ne $totalUserCount) {
Add-Content $exportFile "`n$result,"
} else {
Add-Content $exportFile "`n$result"
}
} # end for loop
} # end foreach loop
} # end try
finally
{
# Release resources used by the search
$userResult.Dispose()
}