new-aduser和import-csv无法正常工作 [英] new-aduser and import-csv not working

查看:33
本文介绍了new-aduser和import-csv无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本,该脚本从CSV文件导入其数据.

I've got the following script which imports its data from a CSV file.:

    import-csv CSVfilelocation.csv | 
    new-aduser -name $_.Name -givenname $_.Firstname -surname $_.Lastname -samaccountname $_.samAccountName -userprincipalname ($_.samaccountname+"@dc.contoso.com") -manager $_.Manager -accountpassword (convertto-securestring Password -asplaintext -force) -path "Complete OU path" -Company $_.Company -Description $_.Description -enabled $false

CSV文件仅包含两行数据,第一行包含列标题,第二行包含数据.

The CSV file only contains two rows of data, The first row containing the column headers and the next row the data.

该脚本不会引发错误,但也不会执行任何操作.不会创建用户,脚本会像正在等待输入一样输出>>符号.

The script does not throw an error, but it doesn't do anything either. The user is not created and the scripts outputs the >> sign like it is waiting for input.

Executionpolicy设置为不受限制,并且脚本是从计算机本地运行的.

Executionpolicy is set to unrestricted and the script is run locally from the machine.

为什么不起作用?

推荐答案

您很有可能需要一个明确的 foreach 来多次调用 new-aduser .

Most likely you need an explicit foreach to call new-aduser several times.

import-csv CSVfilelocation.csv | % {
    new-aduser -name $_.Name -givenname $_.Firstname -surname $_.Lastname -samaccountname $_.samAccountName -userprincipalname ($_.samaccountname+"@dc.contoso.com") -manager $_.Manager -accountpassword (convertto-securestring Password -asplaintext -force) -path "Complete OU path" -Company $_.Company -Description $_.Description -enabled $false 
}

我想念您的Powershell等待更多输入.这意味着您在行中的某处有一个未封闭的括号或字符串,因此请检查并修复.

I've missed that your Powershell waits for more input. This means you have an unclosed parentheses or string somewhere in your line, so check and fix.

这篇关于new-aduser和import-csv无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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