通过Powershell True CSV导入用户

时间:2018-12-22 13:56:42

标签: powershell powershell-v4.0 windows-server-2016

每个人都很难在csv文件的帮助下尝试通过powersheel创建新用户,即时通讯并没有使我更明智。

New-ADOrganizationalUnit -Name "Vroege" -ProtectedFromAccidentalDeletion $False
New-ADOrganizationalUnit -Name "Late" -ProtectedFromAccidentalDeletion $False
#importing modules
Import-Module ActiveDirectory
$filepad = Read-Host -Prompt "vul hier het pad in waar de file zig bevind"

$users = Import-Csv $filepad

#LOOP
foreach ($user in $users) {
    #info verzammelen

    $Fname = $user.'First Name'
    $Lname = $user.'Last Name'
    $Officephone = $user.'Office Phone'

    $jtitle = $user.'Job Title'
    $OUpath = $user.'Orgianizational Unit'
    $Password = $user.Password

    #creating users
    New-ADUser -Name "$Fname $Lname" -GivenName $Fname -Surname $Lname -UserPrincipalName "$Fname.$Lname@mvdb.test" -Path $OUpath -AccountPassword ( ConvertTo-SecureString $Password -AsPlainText -Force ) -ChangePasswordAtLogon $False -OfficePhone $Officephone -Enabled $True 


    #echo output

    echo "de account zijn aangemaakt voor $fname $Lname in $OUpath"

    }

这是错误消息,我的想法是直接在

上从CSV文件导入用户
 New-ADUser : No superior reference has been configured for the directory service. The directory service is therefore unable 
to issue referrals to objects outside this forest
At C:\Users\mikevdb_admin\Desktop\Untitled1.ps1:22 char:5
+     New-ADUser -Name "$Fname $Lname" -GivenName $Fname -Surname $Lnam ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (CN=Wes Sieders,OU=Late:String) [New-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8406,Microsoft.ActiveDirectory.Management.Commands.NewADUser

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,结果是我对 -OU 路径的说明是错误的。在阅读了许多帖子后,包括上面评论 #2 中的两个,我 仍然无法配置有效的组合。

幸运的是,我在评论 2 中标记为“那里”的链接中找到了一些有用的信息。 https://activedirectorypro.com/create-bulk-users-active-directory/

在视频中,此人提到指定 -OU 参数是可选的。

我从脚本中删除了 -OU 参数并运行,在用户中创建用户。

这样做可能只对小公司有用。

如果您收到此错误,请仔细查看您的 OU 值。该问题也可能与在 .csv 文件中传入包含逗号的字段有关。我怀疑当您将 Excel 中的数据导出为 .csv 时,它会引用字段,这可能会解决逗号问题。

相关问题