PowerShell InvokeGet the directory property cannot be found

前端 未结 1 609
有刺的猬
有刺的猬 2021-01-28 21:21

We needed to retrieve the information in active directory concerning \'Terminal Services\'. For this I\'ve created a function that works fine most of the time. However, with som

相关标签:
1条回答
  • 2021-01-28 21:42

    I've been working on a recent project that uses ADSI to set and read Terminal Services attributes. From my testing anytime you perform a "InvokeGet({TS Attribute})" a COM exception will be thrown with the message "The directory property cannot be found in cache"

    This seems to occur only when the "userParameters" attribute is not set in AD. Maybe the attribute internally checks the ADSI cache for userParameters? So i'm thinking logically you could check the DirectoryEntry for userParameters first, then try and read the properties, or else set it to construct the blob

    if ($user.Properties.Contains("userParameters"))
    {
     #Read the Property from ADSI
     Write-Host $user.InvokeGet("TerminalServicesProfilePath")
    } else {
     #Set the property to construct the userParameter blob
     $user.InvokeSet("TerminalServicesProfilePath", "\\somepath")
     $user.CommitChanges()
    }
    

    Even if the userParameters attribute is not set, you can still perform an InvokeSet to have it constructed

    0 讨论(0)
提交回复
热议问题