Add Computers to Log On Workstation Attribute (userWorkstations) based on computers in OU. RRS feed

  • Question

  • I need a script that will look at a specific OU, grab the computer object names and add those names into the userWorkstation Attribute for the user I specify.

    I have this which gives me the computer names:

    $computer =dsquery computer "OU=Checkout-Presentation,OU=Workspace,DC=DWT,DC=com" -o rdn 

    Set-ADUser -Identity SA_ZuveDHD -LogonWorkstations $computer

    I'm pretty sure I need some sort of foreach statement but I can't quite wrap my head around how to get this done.   Any help appreciated.

    • Edited by Dave Zuver Thursday, April 11, 2019 11:57 PM
    • Moved by Bill_Stewart Wednesday, September 4, 2019 9:15 PM Abandoned
    Thursday, April 11, 2019 11:53 PM

All replies

  • Friday, April 12, 2019 12:11 AM
  • Advise:

    The -LogonWorkStations parameter of the Set-ADUser cmdlet updates the userWorkstations attribute of the specified user. The userWorkstations attribute is a single-valued string. It is a comma delimited list of the NetBIOS names of the computers the user is allowed to logon to. If the attribute has no value, the user can logon to any computer in the domain. You need to construct one variable with all computer names (comma delimited) in the OU, and pass this variable to the -LogonWorkStations parameter. Use the Get-ADComputer cmdlet to retrieve the Names of all computers in the OU. You pass the distinguished name of the OU to the -SearchBase parameter of the Get-ADComputer cmdlet. Check the help for Get-ADComputer for details.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Friday, April 12, 2019 12:26 AM
  • Thank you.

    I think have the Get-ADComputer command okay.  This returns a list of computer in the OU.

    Get-ADComputer -Filter * -SearchBase "OU=Checkout-Presentation,OU=Workspace,DC=DWT,DC=com" |select name

    I can even pipe this to a CSV file if I want.

    The part that is confusing me is how to take those computer and populate the userWorkstation attribute using

    Set-ADUser -Identity UserAlias  -LogonWorkstations 

    Friday, April 12, 2019 12:56 AM
  • Similar to below should work:

    $User = Read-Host "Enter user sAMAccountName"
    $Computers = Get-ADComputer -Filter * -SearchBase "OU=Checkout-Presentation,OU=Workspace,DC=DWT,DC=com" | select Name
    $UserWS = ""
    ForEach ($Computer In $Computers)
        If ($Computer -eq "") {$UserWS = $Computer}
        Else {$UserWS = "$UserWS,$Computer"}
    Set-ADUser -Identity $User -LogonWorkstations $UserWS

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    Friday, April 12, 2019 8:47 AM