我正在尝试使用 powershell 将员工列表导入 AD。该脚本需要更新现有的 AD 对象。
我遇到的问题是,有些用户会有手机号码,有些是内部号码,有些只是扩展名,当我以最基本的形式运行 Set-ADuser 命令时,只要值为空,它似乎就会失败。
我不擅长脚本,谁能向我解释为什么下面的脚本不起作用?如果是这样,有人可以建议如何使其工作吗?干杯
Import-module ActiveDirectory
$CSVPath = "c:\scripts\ictdepartment2.csv"
$csvData = Import-CSV $CSVPath -delimiter "," -Header ("SamaccountName","identity","Title","Company","Department","Description","Office","OfficePhone","IPPhone","MobilePhone")
##
foreach ($line in $csvData)
{
$accountTable = @{
'SamaccountName'= $line.SamaccountName
'identity'= $line.identity
'title'= $line.title
'company'= $line.company
'department'= $line.department
'description'= $line.description
'office'= $line.office
'officephone'= $line.officephone
'IPPhone'= $line.ipPhone
'mobilephone'= $line.mobilephone
}
}
##
ForEach($line in $csvData)
{
$SamaccountName = $line.SamaccountName
$identity = $line.identity
$title = $line.title
$company = $line.company
$department = $line.department
$description = $line.description
$office = $line.office …Run Code Online (Sandbox Code Playgroud)