Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell使用csv在不同的OU中创建广告用户_Powershell_Creation_Ou - Fatal编程技术网

Powershell使用csv在不同的OU中创建广告用户

Powershell使用csv在不同的OU中创建广告用户,powershell,creation,ou,Powershell,Creation,Ou,在Active Directory中创建新用户时遇到问题。 我有一个.csv文件,其中我将用户所在城市指定为多个标题“location”之一,现在我想在与“location”条目匹配的OU中创建用户 例如:“地点”是德累斯顿,而OU是“OU=用户,OU=德累斯顿,OU=德国,DC=acme,DC=com” 位置为“慕尼黑”时相同 OU=用户,OU=慕尼黑,OU=德国,DC=acme,DC=com 我玩过通配符等,但似乎我的大脑中缺少了一个环节,我如何创建一个变量-来自匹配的正确OU来设置正确的路

在Active Directory中创建新用户时遇到问题。 我有一个.csv文件,其中我将用户所在城市指定为多个标题“location”之一,现在我想在与“location”条目匹配的OU中创建用户

例如:“地点”是德累斯顿,而OU是“OU=用户,OU=德累斯顿,OU=德国,DC=acme,DC=com”

位置为“慕尼黑”时相同 OU=用户,OU=慕尼黑,OU=德国,DC=acme,DC=com

我玩过通配符等,但似乎我的大脑中缺少了一个环节,我如何创建一个变量-来自匹配的正确OU来设置正确的路径命令

    $Domain   = 'dc=acme,dc=com'
$OUs = @( #what to put in here to make this to a matching variable?
  "OU=Users,OU=Munich,OU=Germany,",
  "OU=Users,OU=Munich,OU=Germany,",

)
不确定您现在是否能解决我的问题:)


Dschordge

如果您的模式总是相同的,您只需创建一个“模板字符串”,并使用字符串格式运算符(
-f
)将csv中的
位置值拖放到字符串中即可:

$Domain = 'dc=acme,dc=com'
$OUtmpl = "OU=Users,OU={0},OU=Germany,$Domain"

foreach($newUser in Import-Csv path\to.csv)
{
    $OU = $OUtmpl -f $newUser.location
    # create user in $OU here
}