執行效果 執行前 執行後 下面是Powershell 黃底的部分是你想要加入的電腦清單 $users = Get-ADUser -Filter * -SearchBase 'OU=TESTUSERS,DC=pouchen,DC=com' -properties * #This gets all the users in AD Foreach($user in $users){ $usertemp = get-aduser -Identity $user.DistinguishedName -Properties LogonWorkstations $check=$user.LogonWorkstations if ( $check.length -gt 0) { $info=$user.LogonWorkstations + ", DDCP01,DDCP02,ADDCP01,ADDCP02 “ Set-ADUser -Identity $user.DistinguishedName -LogonWorkstations $info $output=$user.SamAccountName + " logon has been set.“ Write-Output $output }else{ $info=" DDCP01,DDCP02,ADDCP01,ADDCP02 “ Set-ADUser -Identity $user.DistinguishedName -LogonWorkstations $info $output=$user.SamAccountName + " logon has been set.“ Write-Output $output } } footer See also :