Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 65
  • Last Modified:

Powershell Question

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
sparkis
Asked:
sparkis
  • 6
  • 2
1 Solution
 
oBdACommented:
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
 
FOXActive Directory/Exchange EngineerCommented:
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
 
sparkisAuthor Commented:
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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
sparkisAuthor Commented:
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
 
sparkisAuthor Commented:
Using -City, -"City"

does not work
0
 
FOXActive Directory/Exchange EngineerCommented:
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
 
sparkisAuthor Commented:
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
 
sparkisAuthor Commented:
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
 
sparkisAuthor Commented:
All set - Thanks
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now