0

假设我有一个 CSV 表,第一行是用户名,第二行是电子邮件地址。

例子:

用户名电子邮件地址


jhornet jhornet@mail.com

我怎样才能以一种安全又好的方式将这些信息导入到 AD 中,也许可以通过签入?

这是我到目前为止所拥有的(没有 CSV):

Import-Module activedirectory

$company = "International"
$username = Get-Content c:\users.txt
$emailadress = Get-Content c:\mail.txt

foreach($user in $username)
{
 Set-ADuser -Identity $user -Company $company
}

#second

foreach($emailadress in $username)
{
Set-ADuser -Identity $user -EmailAddress $emailadress
}

仍然在使用 powershell 学到很多东西,有些东西很难理解并且更好看:)

提前致谢!

格,

JPA

4

1 回答 1

0

我在这里摇摇欲坠,因为我以前从未使用过 AD 命令,但它应该是这样的:

Import-Module activedirectory

$company = "International"
$users = Import-Csv c:\user.csv
$users # dumps users to allow visual inspection
read-host "press Enter to continue or Ctrl+C to abort"
$users | Foreach {Set-ADUser -Identity $_.username -Company $company -whatif}
$users | Foreach {Set-ADUser -Identity $_.username -EmailAddress $_.emailaddress -whatif}

-WhatIf当您认为命令将正常工作时,请删除该参数。

于 2013-11-05T14:47:22.220 回答