两周前,我制作了一个脚本,用于在我的AD上制作批量用户。 我的服务器桌面上有.ps1文件和.csv文件。
通常我可以右键单击.ps1文件并选择“使用Powershell运行”,一切正常。
这次我有了这个。我真的不知道问题是什么:
我的.ps1文件如下:
Import-Module ActiveDirectory
Import-Csv "C:\Users\laurent\Desktop\NewUsers.csv" | ForEach-Object {
$userPrincinpal = $_."samAccountName" + "@cvoww.lokaal"
$weergavenaam = $_."Firstname" + " " + $_."Lastname"
New-ADUser -Name $weergavenaam `
-Path $_."ParentOU" `
-SamAccountName $_."samAccountName" `
-UserPrincipalName $userPrincinpal `
-GivenName $_."Firstname" `
-SurName $_."Lastname" `
-DisplayName $weergavenaam `
-AccountPassword (ConvertTo-SecureString $_."password" -AsPlainText -Force) `
-ChangePasswordAtLogon $true `
-Description $_."description" `
-Enabled $true;
}
Pause
我的csv文件如下:
Firstname,Lastname,samAccountName,description,ParentOU,password
Julles,Coutelle,Julles.Coutelle,"Valerie M, Diverse cursussen","OU=Cursisten1718,DC=cvoww,DC=lokaal",cursist
Walter,Croquey,Walter.Croquey,"Valerie M, Diverse cursussen","OU=Cursisten1718,DC=cvoww,DC=lokaal",cursist
可能是什么问题? 谢谢你的帮助! 劳伦
答案 0 :(得分:0)
只需进行修改,确保其按预期运行:
#Requires -RunAsAdministrator
#Requires -Version 3
Import-Module ActiveDirectory
Import-Csv 'C:\Users\laurent\Desktop\NewUsers.csv' |
ForEach-Object {
$weergavenaam = "$($_.Firstname) $($_.Lastname)"
$Params = @{
Name = $weergavenaam
Path = $_.ParentOU
UserPrincipalName = "$($_.samAccountName)@cvoww.lokaal"
SamAccountName = $_.samAccountName
GivenName = $_.Firstname
SurName = $_.Lastname
DisplayName = $weergavenaam
AccountPassword = (ConvertTo-SecureString $_.password -AsPlainText -Force)
ChangePasswordAtLogon = $True
Description = $_.description
Enabled = $True
}
New-ADUser @Params
}
PAUSE