locked
Get labelComputer and Set it logon workstation RRS feed

  • Question

  • Hi we have AD attribute labelComputer, it show us last logon computer of user, we need to set to all users logon workstation which set in this attribute, can we do it?I write this :

    $Workstation = Get-ADUser -SearchBase "OU=test1,DC=test,DC=local" -Filter * -Properties labelComputer | Select-Object -ExpandProperty labelComputer

    and it show me computer 

    test123

    testnew

    Can I apply this computers for each user for example logon worsktation for user1 will be computer  test123 and for user2 it will be tetnew?


    System administrator



    Wednesday, September 25, 2019 7:28 AM

Answers

  • Are you trying to set the logonworkstations based on some attribute for all the users, try below, I have not checked the same but it might do the job for you if there is only one computer or a comma seperated list in the LabelComputer Attribute:

    Get-ADUser -SearchBase "OU=test1,DC=test,DC=local" -Filter * -Properties *| 
        foreach{
            if($_.LabelComputer){
                Set-ADUser $_.SamAccountName -LogonWorkstations $_.LabelComputer
                Write-Output "$($_.LableComputer) is set as logon computer for $($_.SamAccountName)"
            }
            else{
                Write-Output "LabelComputer Attribute is blank for $($_.SamAccountName)"
            }
    
        } 


    • Edited by DumbleD0re Wednesday, September 25, 2019 11:24 AM
    • Marked as answer by Farid Ahmadov Wednesday, September 25, 2019 11:26 AM
    Wednesday, September 25, 2019 10:07 AM
  • Also, Label is mis-spelled as Lable, my bad :(

    Please change $_.LableComputer to $_.LabelComputer.

    Try this:
    Get-ADUser -SearchBase "OU=test1,DC=test,DC=local" -Filter * -Properties *| 
        foreach{
            if($_.LabelComputer){
                Set-ADUser $_.SamAccountName -LogonWorkstations $_.LabelComputer
                Write-Output "$($_.LabelComputer) is set as logon computer for $($_.SamAccountName)"
            }
            else{
                Write-Output "LabelComputer Attribute is blank for $($_.SamAccountName)"
            }
    
        } 


    • Edited by DumbleD0re Wednesday, September 25, 2019 11:24 AM
    • Marked as answer by Farid Ahmadov Wednesday, September 25, 2019 11:30 AM
    Wednesday, September 25, 2019 11:23 AM

All replies

  • help set-adcomputer -online

    The Parameter is "LogonWorkStations".


    \_(ツ)_/


    • Edited by jrv Wednesday, September 25, 2019 7:46 AM
    Wednesday, September 25, 2019 7:44 AM
  • Hi,

    please check this:

    PowerShell to Add a Workstation to a User’s Log On To Property

    Modify user's logonworkstation with multipile stations list (powershell)

    Regards,


    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" where applicable. This helps the community, keeps the forums tidy, and recognizes useful contributions. Thanks!) Blog: https://blog.pohn.ch/ Twitter: @StoyanChalakov

    Wednesday, September 25, 2019 8:09 AM
  • Ok ya check article but I need use computer which is in the labelComputer in properties of user on each user we have labelComputer wich last logon hostname we must set it host to LogonWorkstation.

    System administrator

    Wednesday, September 25, 2019 8:34 AM
  • Are you trying to set the logonworkstations based on some attribute for all the users, try below, I have not checked the same but it might do the job for you if there is only one computer or a comma seperated list in the LabelComputer Attribute:

    Get-ADUser -SearchBase "OU=test1,DC=test,DC=local" -Filter * -Properties *| 
        foreach{
            if($_.LabelComputer){
                Set-ADUser $_.SamAccountName -LogonWorkstations $_.LabelComputer
                Write-Output "$($_.LableComputer) is set as logon computer for $($_.SamAccountName)"
            }
            else{
                Write-Output "LabelComputer Attribute is blank for $($_.SamAccountName)"
            }
    
        } 


    • Edited by DumbleD0re Wednesday, September 25, 2019 11:24 AM
    • Marked as answer by Farid Ahmadov Wednesday, September 25, 2019 11:26 AM
    Wednesday, September 25, 2019 10:07 AM
  • this script gave me error 

    Set-ADUser : Missing an argument for parameter 'LogonWorkstations'. Specify a parameter of type 'System.String' and try again.
    At line:4 char:42
    +             Set-ADUser $_.SamAccountName -LogonWorkstations -Identity ...
    +                                          ~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
        + FullyQualifiedErrorId : MissingArgument,Microsoft.ActiveDirectory.Management.Commands.SetADUser


    System administrator


    Wednesday, September 25, 2019 10:50 AM
  • From the error message you got, it seems like you have used -Identity in front of -logonWorkstations which is creating the error:


    • Edited by DumbleD0re Wednesday, September 25, 2019 11:06 AM
    Wednesday, September 25, 2019 11:06 AM
  • I write this because with out it I see error

    Set-ADUser : Cannot convert 'Microsoft.ActiveDirectory.Management.ADPropertyValueCollection' to the type 'System.String' required by parameter 'LogonWorkstations'. Specified method is 
    not supported.
    At line:4 char:61
    + ...      Set-ADUser $_.SamAccountName -LogonWorkstations $_.LableComputer
    +                                                          ~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.SetADUser


    System administrator


    Wednesday, September 25, 2019 11:11 AM
  • Are there more than one computer listed in the LableComputer attribute for some of the users?

    Could you Show the output of below for any of the test user:

    Get-ADUser TESTUSER -Properties * | Select LabelComputer


    • Edited by DumbleD0re Wednesday, September 25, 2019 11:16 AM
    Wednesday, September 25, 2019 11:16 AM
  • PS C:\Windows\system32> Get-ADUser testnew -Properties * | Select LabelComputer

    LabelComputer
    -------------
    TEST123

    System administrator

    Wednesday, September 25, 2019 11:20 AM
  • Also, Label is mis-spelled as Lable, my bad :(

    Please change $_.LableComputer to $_.LabelComputer.

    • Marked as answer by Farid Ahmadov Wednesday, September 25, 2019 11:26 AM
    • Unmarked as answer by jrv Wednesday, September 25, 2019 6:05 PM
    Wednesday, September 25, 2019 11:22 AM
  • Also, Label is mis-spelled as Lable, my bad :(

    Please change $_.LableComputer to $_.LabelComputer.

    Try this:
    Get-ADUser -SearchBase "OU=test1,DC=test,DC=local" -Filter * -Properties *| 
        foreach{
            if($_.LabelComputer){
                Set-ADUser $_.SamAccountName -LogonWorkstations $_.LabelComputer
                Write-Output "$($_.LabelComputer) is set as logon computer for $($_.SamAccountName)"
            }
            else{
                Write-Output "LabelComputer Attribute is blank for $($_.SamAccountName)"
            }
    
        } 


    • Edited by DumbleD0re Wednesday, September 25, 2019 11:24 AM
    • Marked as answer by Farid Ahmadov Wednesday, September 25, 2019 11:30 AM
    Wednesday, September 25, 2019 11:23 AM
  • perfect it work !!!! Thank you very much!!!

    System administrator


    Wednesday, September 25, 2019 11:26 AM
  • Please mark the answer that worked for you as the answer so that it may help others as well.
    Wednesday, September 25, 2019 11:27 AM
  • I marked yet

    System administrator

    Wednesday, September 25, 2019 11:28 AM