是否可以枚举通过 [ADSI] 对象的 Invoke() 可用的所有方法和属性? [英] Is it possible to enumerate all methods and properties that are available via Invoke() of an [ADSI] object?

查看:45
本文介绍了是否可以枚举通过 [ADSI] 对象的 Invoke() 可用的所有方法和属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇是否有人可以将如何通过绑定实例枚举可用的 ADSI 方法为 [ADSI]$instance.psbase.Invoke()?

I am curious if someone can describe how to enumerate ADSI methods available via a bound instance as [ADSI]$instance.psbase.Invoke()?

研究结果 "参考 ADSI 接口的文档".但我对这个答案并不特别满意.

Research has turned up "refer to the docs for the ADSI interface". but I am not particularly happy with that answer.

如果我实例化:

[ADSI]$lhost_group="WinNT://./Administrators,group"

然后尝试:

@($lhost_group.psbase.Invoke("Members")) | foreach-object {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}

Powershell 将为组中包含的每个对象返回 GetProperty("Name")out.

Powershell will return the out of GetProperty("Name") for each object contained in the group.

如何枚举可通过任何给定 ADSI 接口使用的所有可用方法和属性?

How do I enumerate all of the available methods and properties that would be available via any given ADSI interface?

Shay Levy 的这个答案 是另一个语法示例,其中 [ADSI]$_.GetTypes().InvokeMember()[ADSI]$_.psbase.Invoke() 被使用.

This answer from Shay Levy is another example of syntax where [ADSI]$_.GetTypes().InvokeMember() and [ADSI]$_.psbase.Invoke() are used.

推荐答案

答案是否定的,而且不太可能改变.我对这个答案感到不满,但我可以提供一些技术背景来支持和解释它.

The answer is 'no' and it is unlikely to change. I share your unhappiness with that answer, but I can provide some technical background to support and explain it.

核心问题是本机代码 ADSI 对象必须实现 COM 接口 IDispatch [允许调用后期绑定方法],但它们不一定实现 ITypeInfo [允许类似反射的行为].在 PowerShell 中,实现 IDispatch 而不是 ITypeInfo 的 COM 对象会导致一组奇怪的限制,这就是您所注意到的.

The core problem is that the native-code ADSI objects must implement the COM interface IDispatch [which allows late-bound methods to be called], but they don't necessarily implement ITypeInfo [which allows reflection-like behavior]. In PowerShell, a COM object that implements IDispatch but not ITypeInfo results in odd set of restrictions, which is what you are noticing.

WinNT ADSI 提供程序至少已有 15 年的历史,它从来都不是一个强大的功能.它是 Active Directory 发布之前编写的占位符(早于 CLR 或 PowerShell.)当时,Microsoft 的脚本"意味着早期版本的 VBScript,对 JScript 有一些支持,两者都依赖于在 IDispatch 上,从未使用过 ITypeInfo.

The WinNT ADSI provider is at least 15 years old, and it was never a strong feature. It was a placeholder written before Active Directory shipped (way before the CLR or PowerShell.) Back then, 'scripting' at Microsoft meant early versions of VBScript, with with some support for JScript, both of which relied on IDispatch and never used ITypeInfo.

这是 PowerShell 早期讨论的一个话题,当时 PowerShell 团队成员之一说:

This was a topic of discussion early in PowerShell's life, when one of the PowerShell team member said:

2006 年 7 月 14 日

14 Jul 2006

... PowerShell 无法显示 COM 对象的方法,如果 ITypeInfo不提供接口.这将很快得到修复.解决方法是使用Type.InvokeMethod().

... The PowerShell can't show the methods of COM objects if the ITypeInfo interface is not provided. This will be fixed soon. The workaround is to use Type.InvokeMethod().

PowerShell 对 COM 对象的支持有所改进,但从未实现过完整的修复.我认为团队成员可能过度承诺了技术上的可能性.这可能让人们感到困惑.几年前,我向团队中的一位开发人员首席朋友询问了这个问题;他显然熟悉这个问题,并表示用例不是高优先级,并提到了解决方法.

There have been improvements in PowerShell's support of COM objects, but a complete fix never materialized. I think the team member may have over-promised what is technically possible. This may have confused people. I asked a developer lead friend of mine on the team about this a couple of years ago; he was clearly familiar with the issue and indicated that the use-case wasn't a high-priority and mentioned the workaround too.

PowerShell 团队一直在发布令人印象深刻的功能和一些错误修复,但坦率地说,我认为这个问题不会成为错误栏.

The PowerShell team has been shipping impressive features and some bug-fixes, but frankly I don't think this issue will ever make the bug bar.

这篇关于是否可以枚举通过 [ADSI] 对象的 Invoke() 可用的所有方法和属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆