Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

Return DirectoryServices.DirectoryEntry object from function

$
0
0

I'm writing a powershell script that will bind to a user object and then change some attributes on the object.  I have a function that binds to the user object successfully. However when I attempt to return that user object so it can be used in another function that will manipulate the object I get the following error.  Any help or suggestions would be very much appreciated.  thanks,

pm

format-default : The following exception occurred while retrieving members: "Unknown error (0x8000500c)"
    + CategoryInfo          : NotSpecified: (:) [format-default], ExtendedTypeSystemException
    + FullyQualifiedErrorId : CatchFromBaseGetMembers,Microsoft.PowerShell.Commands.FormatDefaultCommand

Here is the function:   

Function GetUser ($szCN) {
Try {
$userCN = "cn=" + $szCN
$userDN = $userCN + "," + $szOU
$szUserContext = "LDAP://" + $szIDVServer + "/" + $userCN + "," + $szOU

$msg = "Attempting to bind to user: " +  $szCN
debug $msg

if ($verb) {$verbMsg = "User DN: " + $userDN
debug $verbMsg
debug ''
}

$objUser = New-Object System.DirectoryServices.DirectoryEntry($szUserContext, $userID, $pwd, $szAuth)
}
Catch {
$errMsg = $Error[0].Exception.InnerException.Message.ToString().Trim() 
$type = 3
  $entryType = 'Error'
$msg = ' The following error occurred when attempting to bind to user: ' + $userDN +  '.'
debug $msg
debug $errMsg
WriteToLogFile $logFile $msg $type
debug $errMsg
WriteToLogFile $logFile $errMsg
}
Return $objUser
}


pete


Viewing all articles
Browse latest Browse all 2562

Trending Articles