在不覆盖以前的工作站的情况下为用户添加计算机到LogonWorkstation

时间:2017-12-14 11:02:16

标签: powershell active-directory powershell-v2.0 powershell-v3.0

我正在使用此命令

 Set-ADUser xyz -LogonWorkstations "$sysName1,$sysName1"

如果我向xyz用户添加第三个系统,那么之前的系统会被第三个系统覆盖。我想添加第三个系统以及这两个系统。

1 个答案:

答案 0 :(得分:1)

LogonWorkstations属性是一个逗号分隔的字符串,因此您可以获取其值,然后在分配之前将新工作站添加到此。

$User = "xyz"
$NewWorkstation = "Workstation03"

$LogonWorkstations = Get-AdUser -Identity $User -Properties LogonWorkstations | select -ExpandProperty LogonWorkstations #get current computernames that user can access

if ($LogonWorkstations) {
    Set-ADUser -Identity $User -LogonWorkstations "$LogonWorkstations,$NewWorkstation" #add new workstation to existing entries
}
else { 
    Set-ADUser -Identity $User -LogonWorkstations $NewWorkstation #only add new workstation
}