我正在创建我认为是超简单的PowerShell脚本,用“Mobile:”+移动电话号码更新位置字段。使用GAL上的有限字段显示所有用户的手机号码。
不知何故,我只得到没有号码的“手机:”。我尝试了同一个脚本的许多变体,但最终$ User.mobile不正确。
Import-Module ActiveDirectory
$Userlist = Get-ADUser -Server XXXXX -filter * -SearchBase "OU=Users,OU=Corporate,OU=XXXXXXXX,DC=XXXXXX,DC=com"
foreach ($User in $Userlist) {
$newlocation = "Mobile: "
$newlocation = $newlocation + $User.mobile
Set-ADUser -Instance $User
}
# Update properties.
答案 0 :(得分:0)
您需要在此处更改两件事:
在原始mobile
查询中包含location
和Get-ADUser
属性,默认情况下不会检索这些属性:
$Userlist = Get-ADUser -Server XXXXX -filter * -Properties mobile,physicalDeliveryOfficeName -SearchBase "OU=Users,OU=Corporate,OU=XXXXXXXX,DC=XXXXXX,DC=com"
然后确保在调用$User
之前实际修改 Set-ADUser
对象:
foreach ($User in $Userlist) {
$newlocation = "Mobile: " + $User.mobile
$User.physicalDeliveryOfficeName = $newlocation
Set-ADUser -Instance $User
}
答案 1 :(得分:0)
Get-AdUser添加-properties就是答案。它就像一个魅力。
$ Userlist = Get-ADUser -Server XXXXX -filter * -Properties mobile,physicalDeliveryOfficeName -SearchBase“OU = Users,OU = Corporate,OU = XXXXXXXX,DC = XXXXXX,DC = com”
foreach($ userlist中的用户)
{
$newlocation = "Mobile: " + $User.mobile
$User.physicalDeliveryOfficeName = $newlocation
Set-ADUser -Instance $User
}