PowerShell ADSI query leads to 0x80020006 (DISP_E_UNKNOWNNAME))"

0

The query for some AD users TS Home Directory below, leads to an DotNetException. What is wrong with my code? And what is this exception trying to tell me?

$userObject = Get-ADUser someUser -Properties *
$userObject.userParameters

$adsiObject = [adsi]"LDAP://$($userObject.DistinguishedName)"
$adsiObject.PSBase.InvokeGet("TerminalServicesHomeDirectory"); 

Output:

                                                PCtxCfgPresent㔵攱戰ぢCtxCfgFlags1〰て〲〹CtxCallback〰〰〰〰CtxShadow㌰〰〰〰(CtxMaxConnectionTime〰〰〰〰.CtxMaxDisconnectionTime〰〰〰〰CtxMaxIdleTime〰〰〰〰"CtxKeyboardLayout〰〰〰〰*CtxMinEncryptionLevel
㄰ CtxWorkDirectory〰 CtxNWLogonServer〰CtxWFHomeDir〰"CtxWFHomeDirDrive〰 CtxWFProfilePath〰"CtxInitialProgram〰"CtxCallbackNumber〰

Exception calling "InvokeGet" with "1" argument(s): "Unknown name. (Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME))"
At D:\SourceCode\PowerShell\Get-ADTSProperties.ps1:125 char:1
+ $adsiObject.PSBase.InvokeGet("TerminalServicesHomeDirectory");
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

So the attribute userParameters is there and holds data.

.net
powershell
exception

1 Answer

2

I figured it out by myself. The library tsuserex.dll was not registered which provides exports to read the userParameters BLOB.

How to read msTSProfilePath, msTSHomeDrive and msTSHomeDirectory properties from AD (VB.NET)

answered on Stack Overflow Jul 3, 2015 by Matthias Güntert

User contributions licensed under CC BY-SA 3.0