powershell脚本广告脚本组

时间:2013-06-04 14:27:14

标签: powershell

我有以下ps脚本从域本地组导入域/林中的用户详细信息,一切正常,但我需要在excel中包含两个更多详细信息,用户邮件和用户域。我怎么能这样做?

Get-ADGroupMember "test" | Select-Object samaccountname, name, distinguishedname | Export-CSV -path "c:\test.csv" -notypeinformation

1 个答案:

答案 0 :(得分:0)

某些属性未包含在用户对象的默认属性集中。在这种情况下,您需要使用其他(或所有)属性查询用户,例如:

Get-ADGroupMember "test" `
  | Get-ADUser -Properties * `
  | select samaccountname, name, distinguishedname, mail  `
  | Export-CSV "C:\test.csv" -NoTypeInformation

AFAIK(DNS)域名不是AD属性,但您可以从专有名称派生它:

(Get-ADUser "name").distinguishedName -replace '^.*?,dc=' -replace ',dc=', '.'

所以你可以在select语句中添加另一个属性,如下所示:

@{n="domain";e={$_.distinguishedName -replace '^.*?,dc=' -replace ',dc=', '.'}}

至于引荐错误:该组似乎包含来自其他域的成员。 AFAIK必须满足以下所有要求才能对同一林中的其他域运行AD PowerShell cmdlet:

  • 远程域的至少一个DC上的Active Directory Web Services must be running,并且该端口必须可从本地域访问。
  • 您的帐户必须具有远程DC的管理员权限(例如,通过成为Enterprise Admins组的成员)。