Solved

Powershell Question

Posted on 2016-09-08
9
50 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 84

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
This tutorial will walk an individual through the steps necessary to install and configure the Windows Server Backup Utility. Directly connect an external storage device such as a USB drive, or CD\DVD burner: If the device is a USB drive, ensure i…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

730 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