从csv文件导入用户 - 无法正常工作

时间:2017-12-09 05:47:17

标签: powershell

我正在尝试从csv文件导入用户,但目前收到错误。我得到的错误是"无法验证参数' Path'"提供非空或空的参数"

   Import-Module ActiveDirectory

$filepath = Read-Host -Prompt "Please enter the path to your CSV file"

$securePassword = ConvertTo-SecureString "TESTpassw0rd!" -AsPlainText -Force

$users = Import-Csv $filepath

ForEach ($user in $users) {

$fnavn = $user."Fornavn"
$enavn = $user."Etternavn"
$ansattId = $user."AnsattID"
$OUpath = $user."Oorganizational Unit"

New-ADUser -Name "$fnavn $enavn" -GivenName $fnavn -Surname $enavn -UserPrincipalName "$fnavn.$enavn" -Path $OUpath -AccountPassword $securePassword -ChangePasswordAtLogon $True -AnsattID $ansattId -Enabled $True


echo "Account created for $fnavn $enavn in $OUpath"

}

0 个答案:

没有答案