Solved

Powershell Question

Posted on 2016-09-08
9
53 Views
Last Modified: 2016-09-09
I ran a PS to update the "City" AD attribute. (on a win2k8r2 server)

 Set-ADUser -Replace @{ l="$($user.City)"}

Open in new window


From this site: http://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx

It says the lDAPDisplayName for "city" is "l"

What happened is the attribute for "City" was properly updated...BUT... this value was also assigned to the attribute "LogonWorkstations"

Anyone know how to avoid this?

Thanks,
0
Comment
Question by:sparkis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 500 total points
ID: 41789746
Can't reproduce, try as I might (though on W2k12 AD); could it be that this is just a leftover from some other (failed) attempt at scripting AD changes?
PS C:\> Get-ADUser -Identity jdoe -Property l, logonWorkstations | Select l, logonWorkstations | fl

l                 :
logonWorkstations :

PS C:\> Set-ADUser -Identity jdoe -Replace @{l = 'Experts Exchange'}
PS C:\> Get-ADUser -Identity jdoe -Property l, logonWorkstations | Select l, logonWorkstations | fl

l                 : Experts Exchange
logonWorkstations :

Open in new window

0
 
LVL 16

Expert Comment

by:FOX
ID: 41789834
Going forward to either replace the city or add the city to a user all you have to do is
Set-Aduser username -City "NameofCity"                   (city has to be in quotes)

Replace switch with a hash table command is not needed

If you haven't cleared the logonworkstations entry yet you will run the command
Set-Aduser username -Logonworkstations $null
0
 

Author Comment

by:sparkis
ID: 41790307
I will try replacing the ldapdisplayname with "City" does it need to be in quotes like this this is a bulk job pulling data from csv

 Set-ADUser -Replace @{ "City"="$($user.City)"}

Open in new window

0
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 

Author Comment

by:sparkis
ID: 41790310
it is not "leftover" the attribute was not there before I ran the script and was there - and put into affect - locking the user out of everything - after I ran the script.
0
 

Author Comment

by:sparkis
ID: 41790342
Using -City, -"City"

does not work
0
 
LVL 16

Expert Comment

by:FOX
ID: 41790536
Sparkis please try to be clear next time about having a .csv and so forth.   I assume you have a .csv with your usernames.
At the top of the column that has your usernames name it users.
You will right-click the powershell icon (run as administrator)
commands will be the following

Import-Module ActiveDirectory                                                                                                            press enter
Import-csv "c:\temp\users.csv" | foreach{Set-ADUser $_.users -City "cityname"}                      press enter

If you have a row of usernames and a row of cities(different cities for users), name the top of cities column City and the command will be
Import-csv "c:\temp\users.csv" | foreach{Set-ADUser $_.users -City $_.City}
0
 

Author Comment

by:sparkis
ID: 41791142
That was all done correctly and was not the OP issue. The issue is not occurring. I re-ran the script and checked and the LogonWorkstation attr was not touched this time. I will cough it up as a fluke.
0
 

Author Comment

by:sparkis
ID: 41791144
For anyone that wants to use it this script was very useful
 
$users = Import-csv -Path "C:\Users\user\Documents\ Staff.csv"
            
foreach ($user in $users) {
Get-ADUser -Filter "sAMAccountName -eq '$($user.samaccount)'" -Properties * -SearchBase "ou=New York,dc=greenbriarequity,dc=com" |
 Set-ADUser -Replace @{
 l="$($user.City)";
 mobile="$($user.Cell)";
 telephoneNumber="$($user.Telephone)";
 facsimileTelephoneNumber="$($user.Fax)";
 title="$($user.Title)";
 st="$($user.State)";
 postalCode="$($user.PCode)";
 streetAddress="$($user.Street)";
 company="$($user.Company)"}
}

Open in new window

0
 

Author Closing Comment

by:sparkis
ID: 41791146
All set - Thanks
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A brief introduction to what I consider to be the best editor for PowerShell.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question