PowerShell创建批量用户

发布于 2025-01-11 07:44:46 字数 1444 浏览 0 评论 0原文

我想提前道歉,我知道这将是我忽略的事情,但我花了几个小时试图让它正常工作。代码在底部。

我正在尝试创建一个自动脚本来根据使用 PowerShell 发送到 DL 的电子邮件来创建用户。我不太精通,并且已经用尽了网络和我拥有的所有书籍。我已经让它工作了,但有一些错误。

AD 中用户登录名下“帐户”选项卡下的错误

  1. 域字段留空
  2. : “Active Directory 管理中心”和“属性”下的 。对于代理,未设置 SMTP。
Import-Module ActiveDirectory
$Users = Import-Csv -Path "C:\Script\newusers2022.csv"            
foreach ($User in $Users)            
{            
   $Displayname = $User.FirstName + " " + $User.Lastname            
   $UserFirstname = $User.Firstname            
   $UserLastname = $User.Lastname  
   $UserEmployeeID = $User.EmployeeID          
   $OU = $User.OU           
   $SAM = $User.FirstName + "." + $User.Lastname            
   $UPN = $User.Firstname + "." +  $User.Lastname + "@" + $User.Mydomain.com
   $EmailAddress = $User.Firstname + "." +  $User.Lastname + "@" + $User.Mydomain.com            
   $Description = $User.Description            
   $Password = "RandomColor1" + "RandomGenPass" + "!"     
   New-ADUser -Name $Displayname -DisplayName $Displayname -SamAccountName $SAM -UserPrincipalName $UPN -GivenName $UserFirstname -Surname $UserLastname -Emailaddress $Email -EmployeeID $UserEmployeeID -Description $Description -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path "$OU" -ChangePasswordAtLogon $true -PasswordNeverExpires $false
   Write-Host $User.SAM "created successfully"
}  

I want to apologize in advance I know this is going to be something I am overlooking but I have spent hours trying to get this to work right. Code is at the bottom.

I am trying to create an automated script to create users based on an email sent to a DL with PowerShell. I am not that versed and have exhausted the web and all the books I have. I have gotten it to work but with some errors.

Errors

  1. In AD under the Account tab under the user logon name: the domain field was left empty
  2. Under Active Directory Administrative Center, and Attributes. For Proxy the SMTP was not set.
Import-Module ActiveDirectory
$Users = Import-Csv -Path "C:\Script\newusers2022.csv"            
foreach ($User in $Users)            
{            
   $Displayname = $User.FirstName + " " + $User.Lastname            
   $UserFirstname = $User.Firstname            
   $UserLastname = $User.Lastname  
   $UserEmployeeID = $User.EmployeeID          
   $OU = $User.OU           
   $SAM = $User.FirstName + "." + $User.Lastname            
   $UPN = $User.Firstname + "." +  $User.Lastname + "@" + $User.Mydomain.com
   $EmailAddress = $User.Firstname + "." +  $User.Lastname + "@" + $User.Mydomain.com            
   $Description = $User.Description            
   $Password = "RandomColor1" + "RandomGenPass" + "!"     
   New-ADUser -Name $Displayname -DisplayName $Displayname -SamAccountName $SAM -UserPrincipalName $UPN -GivenName $UserFirstname -Surname $UserLastname -Emailaddress $Email -EmployeeID $UserEmployeeID -Description $Description -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path "$OU" -ChangePasswordAtLogon $true -PasswordNeverExpires $false
   Write-Host $User.SAM "created successfully"
}  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

手长情犹 2025-01-18 07:44:46

我在我的变量中看到了错误。而且还添加了 proxyAddress 变量。

I see the error in my variable. But also added the proxyAddress variable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文