如何使用powershell更改所有用户的广告电子邮件联系人

use*_*877 2 powershell active-directory

我需要一个脚本来更改我所有的广告用户电子邮件联系字段信息。格式将为“SAMAccountName + @domain.com”。我是一个 powershell 菜鸟,需要一些语法方面的帮助。任何帮助,将不胜感激。

Mat*_*sen 5

这是我会做的:

安装 Active Directory Powershell 模块

像这样编写脚本:

Import-Module ActiveDirectory
$users = Get-ADUser -Filter *
foreach ($user in $users)
{
    $email = $user.samaccountname + '@domain.com'
    Set-ADUser -Identity $user.samaccountname -EmailAddress $email
}
Run Code Online (Sandbox Code Playgroud)