Skip to content

[adsi] type accelerator is unavailable / throws an exception #3266

Closed

Description

Steps to reproduce

[adsi]

Expected behavior

The code should return a System.RuntimeType representing the System.DirectoryServices.DirectoryEntry class, similar to the full version of PowerShell.

PS D:\Users\tsulli\sshscan> [adsi].GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
False    True     RuntimeType                              System.Reflection.TypeInfo

Actual behavior

Throws an exception.

PS /Users/tsulli> [adsi]
Unable to find type [adsi].
At line:1 char:1
+ [adsi]
+ ~~~~~~
    + CategoryInfo          : InvalidOperation: (adsi:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Environment data

Name                           Value
----                           -----
PSVersion                      6.0.0-alpha
PSEdition                      Core
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   3.0.0.0
GitCommitId                    v6.0.0-alpha.15
CLRVersion
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Cheers,
Trevor Sullivan
Docker Captain
Microsoft MVP: Cloud & Data Center Management
https://trevorsullivan.net
https://twitter.com/pcgeek86

Activity

  1. iSazonov commented on Mar 6, 2017

    @iSazonov
    Collaborator

    Following types not in CoreCLR:

    • adsi
    • adsisearcher
    • wmi
    • wmiclass
    • wmisearcher
    • mailaddress
  2. added
    Issue-Enhancement
    on Mar 6, 2017
  3. added
    Up-for-Grabs
    on Mar 6, 2017
  4. BrucePay commented on Mar 6, 2017

    @BrucePay
    Collaborator

    Steve Lee (@SteveL-MSFT) Do we have any idea when the active directory types are going to be added to CoreClr? You can't add the accelerators until the underlying types are there so marking this "up for grabs" is kind of pointless.

  5. removed
    Up-for-Grabs
    on Mar 6, 2017
  6. SteveL-MSFT commented on Mar 6, 2017

    @SteveL-MSFT
    Member

    Bruce Payette (@BrucePay) no idea, not a focus for PS Core 6.0.0

  7. iSazonov commented on Mar 6, 2017

    @iSazonov
    Collaborator

    They've just added to CoreFX without tests. The work has high priority for .NET Standard 2.0
    https://github.com/dotnet/corefx/issues/2089#issuecomment-261681168

  8. added
    Waiting - DotNetCore
    on Mar 6, 2017
  9. iSazonov commented on Sep 15, 2017

    @iSazonov
    Collaborator

    CoreFX change milestone to 2.1.0. System.DirectoryServices is still unstable.

  10. iSazonov commented on Sep 27, 2017

    @iSazonov
    Collaborator

    Steve Lee (@SteveL-MSFT) Dongbo Wang (@daxian-dbw) I believe it is important features for Enterprises and we should enable its.
    Currently there is no progress in CoreFX with System.DirectoryServices. So I think we should enable it for Windows only.

    It seems we cannot directly reference in GAC System.DirectoryServices .
    Is there a way to solve this problem?

  11. added this to the milestone on Sep 27, 2017
  12. SteveL-MSFT commented on Sep 27, 2017

    @SteveL-MSFT
    Member

    I think we should defer this to 6.1.0 given we should depend on corefx. Perhaps we should suppress the type accelerator for now.

  13. iSazonov commented on Sep 27, 2017

    @iSazonov
    Collaborator

    In CoreFX repo comments say that it depends very much on COM, also, there is no port LDAP library yet. I believe that this will not be done much longer. That's why I'm requesting to enable it on Windows based on GAC dlls.

  14. SteveL-MSFT commented on Sep 27, 2017

    @SteveL-MSFT
    Member

    I'm not sure if we want to set a precedent on creating a dependency on the GAC from PSCore. cc Dongbo Wang (@daxian-dbw)

  15. daxian-dbw commented on Sep 27, 2017

    @daxian-dbw
    Member

    It seems DirectoryServices code is available in corefx: https://github.com/dotnet/corefx/tree/master/src/System.DirectoryServices/src/System/DirectoryServices
    and the preview version nuget package for System.DirectoryServices is also available on dotnet-core feed (https://dotnet.myget.org/feed/dotnet-core/package/nuget/System.DirectoryServices).
    Can't we wait for that to mature and depend on that instead?

  16. 4 remaining items

  17. iSazonov commented on Sep 29, 2017

    @iSazonov
    Collaborator

    I thought about this and about our compatibility module.
    My concerns:

    1. I don't believe that the module will be ready in RTM time.
    2. I see we have codes for DirectoryEntry (ExtendedAdapter and etc.) - it could be the main breaking change.

    Suggestion is - create temporary nuget package to expose the GAC dll until CoreFX issue a ported version.

    I think too many Windows users will be forced to use workarounds - why should we rob them? :-)

  18. SteveL-MSFT commented on Nov 1, 2017

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee reviewed this and agreed we should not take explicitly dependency on assemblies in the GAC. However, to resolve this class of issues, we agreed that we should have a module like "WindowsPSModulePath" to create aliases that have been excluded from PSCore6. Steve to work on that module. Leaving this issue until DirectoryEntry shows up in corefx.

  19. added
    Committee-Reviewed
    and removed
    Review - Committee
    on Nov 2, 2017
  20. SteveL-MSFT commented on Nov 2, 2017

    @SteveL-MSFT
    Member

    Unfortunately, it appears my workaround isn't complete so I can't actually enable this in my module. Currently, we explicitly #ifdef out the type convertors for ADSI (and WMI) as the type doesn't exist in corefx. Without the type convertors, it's only a partial solution to manually add the type accelerator.

  21. lzybkr commented on Nov 2, 2017

    @lzybkr
    Contributor

    It would be useful to have a "delay resolved" type accelerator - that would help startup performance a bit by not eagerly loading all the assemblies referenced by accelerators, and as a bonus, you could add the adsi accelerator in the core.

    That said, I never implemented this idea because I was pretty sure some other code running during startup would just load the assemblies I was trying to defer.

  22. dronkoff commented on Jan 15, 2018

    @dronkoff

    So, gentleman, can I search in AD from PS Core 6.0 or need to wait for future releases?

  23. iSazonov commented on Jan 15, 2018

    @iSazonov
    Collaborator
  24. markekraus commented on Jan 15, 2018

    @markekraus
    Contributor

    Vladimir (@dronkoff) the PSCoreWindowsCompat module will add most of the .NET System.DirectoryServices namespace back (Only works on windows, no support for macOS or Linux). The ADSI type accelerators and the special things PS does with them are not available.

  25. dronkoff commented on Jan 15, 2018

    @dronkoff

    Guys, that works for me. Thanks Mark Kraus (@markekraus) !

    if($PSVersionTable.PSEdition -eq 'Core')
    {
        if(-not $IsWindows)
        {
            throw "This works only on Windows."
        }
        if(-not (Get-Module PSCoreWindowsCompat -ListAvailable))
        {
           Install-Module PSCoreWindowsCompat -Scope CurrentUser
        }
        Import-Module PSCoreWindowsCompat -ErrorAction Stop
        Add-Type -AssemblyName ${env:windir}\microsoft.net\framework64\v4.0.30319\system.directoryservices.dll
        [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::add("adsi","System.DirectoryServices.DirectoryEntry")
        [psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::add("adsisearcher","System.DirectoryServices.DirectorySearcher")
    }

    Is it an official way (workaround) from PS team?

  26. iSazonov commented on Jan 15, 2018

    @iSazonov
    Collaborator

    We consider Windows Compatibility Pack as an opportunity to return back the excluded features in PowerShell Core on Windows until .Net Core implement the APIs.
    Currently Windows Compatibility Pack is still preview.

  27. removed
    Waiting - DotNetCore
    on Jun 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Committee-ReviewedIssue-EnhancementResolution-Fixed

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions