Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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根据员工ID修改Active Directory用户属性?_Powershell - Fatal编程技术网

如何使用Powershell根据员工ID修改Active Directory用户属性?

如何使用Powershell根据员工ID修改Active Directory用户属性?,powershell,Powershell,我试图通过用户的EmployeeID而不是他们的SAMAccountName来更新用户的广告属性。我尝试过使用Set ADUser,但它不起作用,因为我收到的列表中没有帐户sAMAccountName,因为它来自无权访问此信息的HR 是否有办法通过其唯一的employeeID更新广告用户属性 我的源数据.csv文件包含以下内容: EmployeeID;company;department;title;country;postalCode;city;streetAddress;manager 28

我试图通过用户的
EmployeeID
而不是他们的
SAMAccountName
来更新用户的广告属性。我尝试过使用
Set ADUser
,但它不起作用,因为我收到的列表中没有帐户
sAMAccountName
,因为它来自无权访问此信息的HR

是否有办法通过其唯一的
employeeID
更新广告用户属性

我的源数据.csv文件包含以下内容:

EmployeeID;company;department;title;country;postalCode;city;streetAddress;manager 2828;TEST1;TEST2;TestXENUser;DE;12345;MUE;Miller Street 6;chrtest
$Users = Import-CSV C:\05042017\data.csv

$Users | ForEach-Object {

    $EmpID = $_.EmployeeID

    Get-ADUser -Filter "*" -Property EmployeeID | Where {$_.EmployeeID -eq $EmpID} | Set-ADUser -company $EmployeeID.company -department $EmployeeID.department –title $EmployeeID.title –country $EmployeeID.country –postalCode $EmployeeID.postalCode –city $EmployeeID.city –streetAddress $EmployeeID.streetAddress –manager $EmployeeID.manager -WhatIf
}
我认为我没有在正确执行
Set ADUser
命令后连接到属性。我自己做了一些测试,但似乎无法让它工作

如何告诉
Set ADUser
命令从.csv文件获取属性?
我以前做过这项工作,但它是这样的:
ForEach$user in$Users
而不是:
ForEach Object

你只需要通过使用
get aduser
并根据EmployeeID过滤结果,获得一个在广告中代表用户的对象,然后将其传输到
set aduser
。例如:

Get-ADUser -Filter "employeeid -eq '$EmpID'" | Set-ADUser <-Attribute> <Value> -WhatIf

在上面的示例中,我们使用了一个
ForEach
循环,该循环处理CSV文件中的每一行(我们已加载到
$Users
),并创建一个值为
$User
的对象。然后,我们可以参考$User的属性(带有.notation),以获取我们在
Set ADUser

中需要的属性值。您应该编辑问题并将其添加到那里,而不是将其作为答案发布。我将根据新信息修改我的答案,我认为
ForEach
循环将更简单/更清晰。我已修改我的答案,根据您提供的CSV标题使用
ForEach
。我还通过匹配
-filter
参数而不是使用
where
,简化了获取用户的方法。出现错误:get ADUser:未识别搜索筛选器。行:2,字母:15+CategoryInfo:NotSpecified:(:)[Get ADUser],ADException+FullyQualifiedErrorId:Der Suchfilter wurde nicht erkannt,Microsoft.Act iveDirectory.Management.Commands.GetAduser奇怪,它在我的环境中工作。然后尝试还原为:
Get ADUser-Filter*-property employeeid |其中{$$.employeeid-eq$User.employeeid}| Set ADUser
这可能比在
-Filter
属性中过滤需要更长的时间才能在大型广告中运行。
$Users = Import-CSV C:\05042017\data.csv -Delimiter ';'

ForEach ($User in $Users) {
    Get-ADUser -Filter "employeeid -eq '$($User.EmployeeID)'" | Set-ADUser -company $User.company -department $User.department –title $User.title –country $User.country –postalCode $User.postalCode –city $User.city –streetAddress $User.streetAddress –manager $User.manager -WhatIf
}