AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 566114
Accepted
Patrick
Patrick
Asked: 2014-01-10 05:57:01 +0800 CST2014-01-10 05:57:01 +0800 CST 2014-01-10 05:57:01 +0800 CST

无法识别 powershell 中项目的属性

  • 772

在尝试回答这个问题时,我遇到了困扰我一段时间的问题,但我一直无法找到答案。

以下脚本块将列出本地管理员组的所有成员的名称。

$group = [ADSI]"WinNT://./Administrators"
@($group.Invoke("Members")) | foreach {$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}

但是,它只会列出名称,而不会列出其他属性。

我相当确定Members我可以提取其他属性,但我不明白我将如何确定其他属性是什么。

我不一定需要知道该项目的其他属性,这更多的是我将如何找到它们的问题。

(如果这有点含糊,我深表歉意,我在这一切方面都是自学成才的,我很清楚我可能会在错误的树上吠叫和/或经常犯可怕的错误。)

powershell
  • 3 3 个回答
  • 1550 Views

3 个回答

  • Voted
  1. Adil Hindistan
    2014-01-10T07:32:18+08:002014-01-10T07:32:18+08:00

    问题是您正在处理一个 COM 对象,而这些对象似乎没有提供一种在 PowerShell 中向您展示所有内容的方法。

    您还可以在此处查看不同(C#)线程上的类似问题:https ://stackoverflow.com/questions/10615019/get-property-names-via-reflection-of-an-com-object

    • 2
  2. Best Answer
    Jacob
    2014-05-15T16:41:12+08:002014-05-15T16:41:12+08:00

    请在此处查看可用属性:

    http://msdn.microsoft.com/en-us/library/aa705950(v=VS.85).aspx

    以及与您的问题类似的示例:

    http://social.technet.microsoft.com/Forums/windowsserver/en-US/b4d51781-e304-45b1-a7b1-c21b62263540/adsi-local-group-enum-from-fancy-powershell-to-simple-foreach- rewrite?forum=winserverpowershell

    由于您已经获得了组的成员名称列表,因此要获取成员的详细信息,我将再次重新查询,除了针对单个用户而不是组。

    PS C:\> $group = [ADSI]"WinNT://./administrators"
    PS C:\> $members = $group.Invoke("Members") | %  {$_.GetType().InvokeMember("name", 'GetProperty', $null, $_, $null) }
    PS C:\> $membersObjects = @() ; $members | % { $membersObjects += [ADSI]"WinNT://./$_" }
    PS C:\> $membersObjects | gm
    
       TypeName: System.DirectoryServices.DirectoryEntry
    
    Name                        MemberType Definition
    ----                        ---------- ----------
    ConvertDNWithBinaryToString CodeMethod static string ConvertDNWithBinaryToString(psobject deInstance, psobject dnWithBinaryInstance)
    ConvertLargeIntegerToInt64  CodeMethod static long ConvertLargeIntegerToInt64(psobject deInstance, psobject largeIntegerInstance)
    AutoUnlockInterval          Property   System.DirectoryServices.PropertyValueCollection AutoUnlockInterval {get;set;}
    BadPasswordAttempts         Property   System.DirectoryServices.PropertyValueCollection BadPasswordAttempts {get;set;}
    Description                 Property   System.DirectoryServices.PropertyValueCollection Description {get;set;}
    FullName                    Property   System.DirectoryServices.PropertyValueCollection FullName {get;set;}
    HomeDirDrive                Property   System.DirectoryServices.PropertyValueCollection HomeDirDrive {get;set;}
    HomeDirectory               Property   System.DirectoryServices.PropertyValueCollection HomeDirectory {get;set;}
    LastLogin                   Property   System.DirectoryServices.PropertyValueCollection LastLogin {get;set;}
    LockoutObservationInterval  Property   System.DirectoryServices.PropertyValueCollection LockoutObservationInterval {get;set;}
    LoginHours                  Property   System.DirectoryServices.PropertyValueCollection LoginHours {get;set;}
    LoginScript                 Property   System.DirectoryServices.PropertyValueCollection LoginScript {get;set;}
    MaxBadPasswordsAllowed      Property   System.DirectoryServices.PropertyValueCollection MaxBadPasswordsAllowed {get;set;}
    MaxPasswordAge              Property   System.DirectoryServices.PropertyValueCollection MaxPasswordAge {get;set;}
    MaxStorage                  Property   System.DirectoryServices.PropertyValueCollection MaxStorage {get;set;}
    MinPasswordAge              Property   System.DirectoryServices.PropertyValueCollection MinPasswordAge {get;set;}
    MinPasswordLength           Property   System.DirectoryServices.PropertyValueCollection MinPasswordLength {get;set;}
    Name                        Property   System.DirectoryServices.PropertyValueCollection Name {get;set;}
    objectSid                   Property   System.DirectoryServices.PropertyValueCollection objectSid {get;set;}
    Parameters                  Property   System.DirectoryServices.PropertyValueCollection Parameters {get;set;}
    PasswordAge                 Property   System.DirectoryServices.PropertyValueCollection PasswordAge {get;set;}
    PasswordExpired             Property   System.DirectoryServices.PropertyValueCollection PasswordExpired {get;set;}
    PasswordHistoryLength       Property   System.DirectoryServices.PropertyValueCollection PasswordHistoryLength {get;set;}
    PrimaryGroupID              Property   System.DirectoryServices.PropertyValueCollection PrimaryGroupID {get;set;}
    Profile                     Property   System.DirectoryServices.PropertyValueCollection Profile {get;set;}
    UserFlags                   Property   System.DirectoryServices.PropertyValueCollection UserFlags {get;set;}
    
    • 1
  3. uSlackr
    2014-05-17T05:44:17+08:002014-05-17T05:44:17+08:00

    扩展@Jacob 的想法。当您枚举组的成员时,只返回字符串对象,而不是 AD 用户对象。因此,唯一可用的属性是字符串属性(即长度等)。您需要使用名称作为 -identity 参数再次查询 AD 以检索用户属性。

    在 AD 中,您可以执行以下操作:

    $(get-adgroup "administrators" -Properties members).members|foreach {get-aduser -identity $_}
    

    我不能代表 WinNT 的代码

    • 1

相关问题

  • 资源锁和电源外壳

  • 脚本 - 如何断开远程桌面会话?

  • 如何限制向通讯组发送到外部地址?

  • Powershell对值与数组的作用不同?

  • Windows Powershell Vim 键绑定

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve