如何根据其部门添加组织单位(OU)中的所有用户 [英] How can I add all users in an organizational units (OUs) based on their Departments

查看:159
本文介绍了如何根据其部门添加组织单位(OU)中的所有用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好b $ bi有这种格式的CSV文件

姓名; GivenName; surename; SamAccountName;部门

john smith; john; smith; j.smith; X

i需要根据他们的部门添加Ous中的所有用户,我尝试在互联网上找到的这个脚本,它工作正常,但我不想添加一个OU中的所有用户,

Hi
i have a CSV file in this format
Name;GivenName;surename;SamAccountName;Department
john smith;john;smith;j.smith;X
i need to add all users in Ous based on their departments, i try this script i found on the internet and it's work fine but i don't want to add all user in one OU ,

Import-Module ActiveDirectory

$ Users = Import-Csv -Delimiter";" -Path" .\reefuser.csv"

foreach($ User in User)

{

$ OU =" OU = test,DC = mytest,DC = pc, DC =本地"

#$ Password = $ User.password

$ Detailedname = $ User.GivenName +" " + $ User.surename

$ UserFirstname = $ User.GivenName

#$ FirstLetterFirstname = $ UserFirstname.substring(0,1)

$ SAM = $ User.SamAccountName

New-ADUser -Name $ Detailedname -SamAccountName $ SAM -UserPrincipalName $ SAM -DisplayName $ Detailedname -GivenName $ user.GivenName -Surname $ user.surename -Enabled $ true - 路径$ OU


}

_________

但是当试图通过改变$ ou行来修改它时
$ OU =" $ User.Department,OU = test,DC = mytest,DC = pc,DC = local"

出现错误

新-ADUser:对象名称语法错误

在C:\。ps1:14 char:5

+     New-ADUser -Name $ Detailedname -SamAccountName $ SAM -UserPrincipalName $ SAM  ... ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          :NotSpecified:(CN = michele ksir ... C = pc,DC = local:String)[New-ADUser],ADException

    + FullyQualifiedErrorId:ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADUser



Import-Module ActiveDirectory
$Users = Import-Csv -Delimiter ";" -Path ".\reefuser.csv"
foreach ($User in $Users)
{
$OU = "OU=test,DC=mytest,DC=pc,DC=local"
# $Password = $User.password
$Detailedname = $User.GivenName + " " + $User.surename
$UserFirstname = $User.GivenName
#$FirstLetterFirstname = $UserFirstname.substring(0,1)
$SAM =$User.SamAccountName
New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -GivenName $user.GivenName -Surname $user.surename -Enabled $true -Path $OU
}
_________
but when try to modify it by alter $ou line by this
$OU="$User.Department,OU=test,DC=mytest,DC=pc,DC=local"
an error appeared
New-ADUser : The object name has bad syntax
At C:\s.ps1:14 char:5
+     New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $SAM  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (CN=michele ksir...C=pc,DC=local:String) [New-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8335,Microsoft.ActiveDirectory.Management.Commands.NewADUser

推荐答案

由此引起的错误:

THE ERRORIS CAUSED BY THIS:

UserPrincipalName不好。 查看AD中UPN的定义。 它不能与SamAccountName相同。它必须有一个域名。

UserPrincipalName is bad.  Look at the definition in AD for UPN.  It cannot be the same as SamAccountName. It must have a domain,.


这篇关于如何根据其部门添加组织单位(OU)中的所有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆