[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Powershell Question

Posted on 2016-09-08
9
Medium Priority
?
61 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 2000 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
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
This tutorial will give a short introduction and overview of Backup Exec 2012 and how to navigate and perform basic functions. Click on the Backup Exec button in the upper left corner. From here, are global settings for the application such as conne…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

649 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