PowerShell创建批量用户
我想提前道歉,我知道这将是我忽略的事情,但我花了几个小时试图让它正常工作。代码在底部。
我正在尝试创建一个自动脚本来根据使用 PowerShell 发送到 DL 的电子邮件来创建用户。我不太精通,并且已经用尽了网络和我拥有的所有书籍。我已经让它工作了,但有一些错误。
AD 中用户登录名下“帐户”选项卡下的错误
- 域字段留空
- : “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
- In AD under the Account tab under the user logon name: the domain field was left empty
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在我的变量中看到了错误。而且还添加了 proxyAddress 变量。
I see the error in my variable. But also added the proxyAddress variable.