【问题标题】:Powershell: Get all User from OU who have empty Description Field and write EA6 tlo descriptionPowershell:从OU中获取所有描述字段为空的用户并编写EA6 tlo描述
【发布时间】:2020-09-24 09:59:54
【问题描述】:

我在一个 OU 中有大约 400 个用户。其中大约 100 个用户的描述字段为空白。现在应该用属性 EA6 中相应的值填充字段 Decriction。我想为此使用powershell。有人可以在这里支持吗? 提前致谢。 赫尔曼

这些可能是第一步。现在,srcpt 应该将 EA1 获取到 $name 中所有用户的变量,并将其写入他们的描述中。

$OUpath = 'OU=XX,OU=XXXX,OU=XXXXXXX,OU=用户,OU=XX,DC=XXX,DC=XXXXXXXXX,DC=XX' $name = Get-AdUser -Filter {(Enabled -eq "True" ) -and (description -notlike '*')} -searchbase $OUpath -Properties Description | Select-Object -ExpandProperty SamAccountName

【问题讨论】:

  • 欢迎来到 SO。你拿了Tour 并阅读了How to Ask 的帮助吗?您需要什么样的支持?您是否尝试过寻找解决方案?我敢肯定有数百个例子来说明如何完成这样的任务——甚至/尤其是在 SO 上。
  • 您可以通过提供-SearchBase 参数来限制对Get-ADUser 的搜索。
  • 刚接触 SO 你可能不知道这一点,但习惯上点击左侧的 ✓ accept the answer that solved your problem。这将帮助其他有类似问题的人更轻松地找到它,并有助于激发人们回答您的问题。

标签: powershell active-directory


【解决方案1】:

要从用户那里获取extensionAttribute6 值,您需要在Get-ADUSer 的-Properties 参数中请求它,就像Description 属性一样,因为默认情况下两者都不返回。

然后,你可以这样做:

$ou     = 'OU=Finance,OU=UserAccounts,DC=FABRIKAM,DC=COM'  # enter the distinguishedName of the OU here
$filter = "Enabled -eq $true -and Description -notlike '*'"

Get-AdUser -Filter $filter -SearchBase $ou -Properties Description, extensionAttribute6 | 
    ForEach-Object {
        $_ | Set-ADUser -Description $_.extensionAttribute6
    }

【讨论】:

  • 嗨西奥,非常感谢。仅将一个错误 $true 更改为 'true' 就是这样。
  • @HermanX 我很高兴听到它对你有用。如果您认为我的回答解决了您的问题,请考虑通过单击左侧的复选标记图标 ✓ 来接受答案。这将帮助其他有类似问题的人更轻松地找到它。
猜你喜欢
  • 2019-06-08
  • 2016-01-25
  • 1970-01-01
  • 2022-12-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多