powershell - 如何获取Windows通用帐户列表的AD属性?

标签 powershell active-directory

我在下面的PowerShell命令中,可以使用这些命令来获取AD中所有用户的属性。

Import-Module ActiveDirectory
$attributes = 'SamAccountName', 'Name', 'Mail', 'PasswordLastSet', 'Enabled',
              'PasswordNeverExpires', 'PasswordExpired'
Get-ADUser -Filter * -Properties $attributes | select $attributes

如果我想要一个特定用户的属性,可以在命令提示符下使用以下示例:
net user /domain testuser

但是,如何获得给定用户列表的AD属性?

因此,到目前为止,我已经尝试了以下方法,但仍无法实现,因为它仅返回给一个用户(不确定如何循环):
Import-Module ActiveDirectory
cd AD:
$Users = gc "C:\AD\accounts.txt"
Get-ADUser -Filter '*' -Properties DisplayName, Office |
  ? { $Users -contains $_.SamAccountName } |
  select DisplayName, Office |
  Export-Csv -Path "C:\AD\output\UserProp_14072016.csv" -NoTypeInformation

我正在寻找该帐户所有者的最后设置的密码(有效或无效)。

能否请你帮忙?

最佳答案

我用来获取任意AD用户列表的一种技术是从文本列表构造ORed LDAP过滤器:

$Users = gc "C:\AD\accounts.txt"

$User_filter = $Users -replace '^','(SamAccountName=' -replace '$',')'
$Filter = "(|$User_filter)"

Get-ADUser -LDAPFilter $Filter  -Properties DisplayName,Office

关于powershell - 如何获取Windows通用帐户列表的AD属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38378434/

相关文章:

powershell - Docker在使用powershell时将图像保存为两倍 - 保存原始字节流

git - 为什么源代码树不是 Git Diff 一个 Powershell 脚本 (ps1)

scripting - 在一台计算机上使用 Powershell 在另一台计算机上执行 Powershell 脚本

powershell - 使用Powershell过滤get-adobject

c# - 从 ADFS 声明授权

powershell - ADFS PowerShell : Scripting Web API (Add-AdfsWebApiApplication) with RuleTemplate in IssuanceTransformRules

c# - 如何知道我的 Windows 用户是域用户?

powershell - 首次使用 powershell 登录时的新密码

java - 使用 Spnego 解密 kerberos 票据

azure - 如何关闭 Office365 Exchange Powershell 连接