Script to change DN attribute in AD to be the same as sAMAccountName

Recently I was asked to change the Display Name for all the users in AD in my organization.  I was asked to do so because the previous AD/Exchange Admin created all accounts using the default of "FirstName MiddleInitial LastName".  The
new staff wanted the Display Name to be "LastName, FirstName MiddleInitial".
I made this change using this script I found on the Internet:
# Pre-Users.ps1 - Change the name & display name of existing users.
# Created by - Amit Tank
$Users = Get-User -ResultSize unlimited | where {$_.RecipientTypeDetails -eq "UserMailbox"}
ForEach ($User in $Users)
$DName = $User.LastName + ", " + $User.FirstName + " " + $user.Initials
$DName = $Dname.Trim()
Set-User $User -Name $DName -DisplayName $DName
Get-User $User | FT Name, DisplayName
$DName = $Null
}When I made this change however it changed the DN of each user and the organization is using google sync and can no longer synchronize with google.I think if I had a script that would change the DN to the value of the user's sAMAccount name it would be fixed. I have setup a test OU where I can test this with just one user.I have found a few scripts that claim that they work and that it can be done, but all of them I try I get various errors. Here is one that I made based from other information I have found:# Get sAMAccountName and
then change DN to be the same.
Get-ADUser -Filter * -SearchBase "OU=TEST,DC=MCCSC,DC=EDU"
ForEach ($User in $Users)
set-aduser -Identity "*" $_.distinguishedname -sAMAccountName
($_.samaccountname)
}When I try running this script I get the following error:Set-ADUser : A positional parameter cannot be found that accepts argument '$null'.I am a realitive PowerShell n00b so I really don't know what the heck it is saying there. I don't think I have any parameters not definded or set null, so I am not sure.If I can get a script that will reliably change just the DN to be the same as the sAMAccountName then I can test it and I think everything will be fine.Can anyone help me a bit with this please?Thanks,Nick

I am going to guess that the first script posted by the OP worked; it renamed the user object (changed the DN) and also assigned a value for displayName. But this is not what the OP wanted, so they want a script to fix the situation; a script that will make
the Common Name (the value of the cn attribute) of the user equal to the sAMAcccountName, and perhaps also assign the desired value for displayName. If so, the following script, which assumes the first script worked for the user, should do what is needed:
$Users
= Get-User -ResultSize unlimited |
where {$_.RecipientTypeDetails
-eq "UserMailbox"}
ForEach ($User
in $Users)
    If (($User.LastName
-ne $Null)
-and ($User.FirstName
-ne $Null))
        $DName
= $User.LastName
+ ", "
+ $User.FirstName
+ " "
+ $User.Initials
        $DName
= $Dname.Trim()
        $LName
= $User.sAMAccountName
        If (($User.Name
-ne $LName)
-and ($User.Name
-ne $DName))
            Set-User
$User -Name
$LName -DisplayName
$DName
        ElseIf ($User.Name
-ne $LName)
            Set-User
$User -Name
$LName
        ElseIf ($User.DisplayName
-ne $Dname)
            Set-User
$User -DisplayName
$DName
        Get-User
$User | FT Name, DisplayName
        $DName
= $Null
        $LName
= $Null
Richard Mueller - MVP Directory Services

Similar Messages

  • How to change colors of individual column bar in the same data series

    in mac numbers, how to change colors of individual column bar in the same data series. The entire column series gets selected in the column bars and cannot select to change colors of specifc bars.

    Hi Kiran,
    no its not possible through Theme editor also ,because these colors are coming from Compiler which u are using.
    Regards,
    Govindu

  • How do i change my iPhone to another iPhone using the same sim but keep all my photos ands everything?

    How do i change my iphone to another iphone using the same sim but keep all my photos and everything?

    Old Phone to New Phone
    http://support.apple.com/kb/HT2109

  • If you lose your phone and you get a replacement . does you imei number change? or do they keep it the same as your old one?

    if you lose your phone and you get a replacement . does you imei number change? or do they keep it the same as your old one?

    Hi
    Every handset has a unique series of identifiers, one of which is the IMEI number, so if you exchanged the handset (for example if it was not working & you were still under warranty) your new handset would have a new IMEI number.
    What Apple do though is if you formally exchange your handset (again, under warranty etc) then they record the change on their system, but also give you a sticker which is meant to attach to the original box. That way, if you come to sell the handset, you have a proper record of why the IMEI number on the handset is different from the IMEI number on the box.

  • While playing my albums in iTunes it has just started playing the first song but will not progress through the other songs on the album. Did I accidentally change setting or are other people having the same trouble? thanks

    While playing my albums in iTunes it has just started playing the first song but will not progress through the other songs on the album. Did I accidentally change setting or are other people having the same trouble? thanks

    Hi there Sing Me A Song,
    You may have changed the Up Next list in iTunes. Take a look at the article below for more information on the Up Next lists and how to edit it.
    iTunes 12 for Mac: Play songs
    -Griff W. 

  • HT1918 I have moved from the US to Canada and can't buy apps now.  How do I change my account so I can do the same things here in Canada?

    I have moved from the US to Canada and can't buy apps now.  How do I change my account so I can do the same things here in Canada?

    Before you try that... have a look at Changing the Country here...
    http://support.apple.com/kb/HT1311
    If no joy... Use the above Link to Contact iTunes.

  • Powershell script to set custom attribute on mailuser returns WARNING: The command completed successfully but no settings of user have been modified.

    I am trying to write a script to enable a mailuser (I do know the difference between mailuser and mailbox) and set a custom attribute for that mailuser.  Every time I run the script I get "WARNING: The command completed successfully but no settings
    of <User DN> have been modified."  Both commands being invoked work when typed manually into the exchange management shell on the exchange server itself.  I am using the same administrator account in the script, and when I login to the
    exchange server to manually run the commands, so it shouldn't be a permission issue.  Here is my script so far.  If anyone can shed some light on what I'm doing wrong, I'd appreciate it.
    $excel = new-object -com excel.application
    $wb = $excel.workbooks.open("c:\temp\testmail8.xlsx")
    $ws = $wb.Worksheets.Item(1)
    $row = 1
    $s = New-PSSession -ConfigurationName microsoft.exchange -ConnectionUri http://<Exchange Server Name>/powershell -Credential [email protected]
    Do {
    $Email = $ws.Cells.Item($row, 1).Value()
    $Cat = $ws.Cells.Item($row, 2).Value()
    invoke-command -Session $s -ScriptBlock {Enable-MailUser -ExternalEmailAddress $($args[0][0] + "@domain.com") -Identity $($args[0][0])} -ArgumentList (,$Email, $Cat)
    invoke-command -Session $s -ScriptBlock {Set-MailUser -Identity $($args[0][0]) -CustomAttribute1 $($args[0][1])} -ArgumentList (,$Email, $Cat)
    $row++
         } While ($ws.Cells.Item($row,1).Value() -ne $null)
    $excel.quit    
    Exit-PSSession

    Hi,
    I'm not sure where is wrong in your script. If you want to get more help about the script troubleshooting, I recommand you to ask a question in Script Center forum for more professional answers:
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/home?forum=ITCG
    As a workaround, please directly create a mail user in EAC and set related custom attribute to have a try.
    Thanks,
    Winnie Liang
    TechNet Community Support

  • I changed my apple ID password and now facetime cannot verify my e-mail address.  I have tried changing my password back but still recieve the same pop up window telling me that the email could not be verified and to check my network but have wifi working

    Please help.  I changed my apple id password and now cannot use facetime and my icloud continues to prompt me for my password and I continue to give it but, I repeatedly am prompted for the password unless I cancel the icloud.  I have tried changing my password back to the password I had before and this did not work.  I have tried to use another e-mail address for facetime and had verified that e-mail address and this did not work.  I do not know how to fix this problem.  I have thought about changing my apple id but am not sure how I would be able to carry over the same credit card number to the new apple ID.  I loved my Mac book Pro because I could facetime my boyfriend while I am working away and now I cannot.  I am starting to hate Mac.

    The idea to jumpstart by change was not the smartest one, but gives you an opportunity to use that "temporary" account as permanent. You do not have a choice cause obviously despite you thinking that old account is no more -it does exist on Apple servers. And if you are unwilling to share your [email protected] with friend, just create one extra [email protected] for your friend. One suggestion - do not use gmail.

  • How to access multiple attributes of a node at the same time in XML AS3

         <chapter id="1" title="">
         <screen title="lesson">
         <swf>EXCEL/CH01/CH01_S01.swf</swf>
         <ltitle>Chapter 1</ltitle>
         <rtitle>Setting Up a Workbook</rtitle>
         <prompt>Choose a lesson</prompt>
         </screen>
         <screen title="lesson" tasks="3">
         <swf>EXCEL/CH01/CH01_S02.swf</swf>
         <ltitle>Chapter 1</ltitle>
         <rtitle>Setting Up a Workbook</rtitle>
         <prompt>Click Next to continue</prompt>
         </screen>
    I have 2 attributes of screen node which are title and tasks.
    how can I access these 2 attributes at the same time in AS3
    Is that correct:
    excel.chapter.screen.(@title == "lesson").@tasks
    Thanks alot in advance.

    var excel:XML = <data>
    <chapter id="1" title=""> 
      <screen title="lesson" tasks="">
       <swf>EXCEL/CH01/CH01_S01.swf</swf>
       <ltitle>Chapter 1</ltitle>
       <rtitle>Setting Up a Workbook</rtitle>
       <prompt>Choose a lesson</prompt>
      </screen>
      <screen title="lesson" tasks="3">
       <swf>EXCEL/CH01/CH01_S02.swf</swf>
       <ltitle>Chapter 1</ltitle>
       <rtitle>Setting Up a Workbook</rtitle>
       <prompt>Click Next to continue</prompt>
      </screen>
    </chapter>
    </data>;
    trace(excel.chapter.screen.(@title == "lesson" && @tasks == "3").toXMLString());
    Note that for this to work (and not throw an error) every screen node needs a tasks attribute.
    In your sample code, the first screen node did not have a tasks attribute, in which case an error is thrown when using @tasks == "3"

  • Read Attributes between different views in the same Component

    Hello,
    I have a attribute-D1 declared in VIEW1 and i need to read it into attribute D2 declared in VIEW2.
    I am planning to read it in DO_PREPARE_OUTPUT method of VIEW2.
    Can you please tell me how can i achieve this without having to create another context node (similar type to VIEW1) in VIEW2 and Binding it.
    Can't I just access the View Controller Class of VIEW1 to read it in VIEW2?
    Quick replies would be great.
    Regards
    Dedeepya C

    Hello again,
    I think i was not very clear in my earlier post. So il explain a bit more clearly this time-
    My requirement is to display a SEARCH+RESULT popup (view) onclick of a link; and the popup display has the result list already fetched for the SEARCH Criteria(defaulted).
    Now what i had to do was have the RESULT LIST TITLE display the number of records fetched.
    So my approach was to -
    1) READ the RESULT Size in EH_ONSEARCH of SEARCH VIEW.
    2) Form the Result Title using method  cl_crm_uiu_gen_tools=>get_result_title into a Public Ins Attribute GV_TITLE.
    3) READ the GV_TITLE from SEARCHVIEW into a local attribute in SEARCHVIEWSET (SEARCH VIEW + RESULT VIEW) LV_TITLE.
    data : lv_result_title type string,
      lv_view_controller type ref to ZL_SEARCHVIEW_IMPL.
      lv_view_controller ?= controller->get_subcontroller_by_viewname( 'Ztest/SearchView' ). "#EC NOTEXT
      if lv_view_controller is bound.
      lv_result_title = lv_view_controller->gv_result_title.
      endif.
      <thtmlb:searchFrame showSearchFields = "TRUE"
                          resultListTitle  = "<%= lv_result_title %>" >
      </thtmlb:searchFrame>
    Now, i noticed during debug, when the SEARCH Popup is triggered the 1st time, the control goes to SEARCHCVIEWSET.HTM 1st (GV_TITLE is initial at this point) and then goes to DO_PREPARE_OUTPUT where the Event Handler for SEARCH is called and where the GV_TITLE is set. Due to this the Result Tab gets the default title RESULT LIST
    Whereas the next time, when i click on SEARCH event on popup, the control 1st goes to EVENT HANDLER (where GV_TITLE is set) and then to SEARCHVIEWSET.HTM, this then sets the correct title for RESULT list.
    I need some pointers on why the control goes to SEARCHVIEWSET 1st before even DO_PREPARE_OUTPUT is called.
    How do i set the RESULT Title in the 1st instance to display the correct no. of records fetched.
    Any help would be appreciable.
    Regards
    Dedeepya

  • Universal Changes (vs. each and every page of the same item)

    Hey All:
    Been working with Dreamweaver (CS5) long enough now to realize there are things I can do, and should do.  Now it's time to learn how.
    My biggest time issue is that I can have the same thing (such as a table or menu) on each page.  So if I change an item on one page I then have to go change that item (such as a menu item label) in all other pages where it appears.
    Is there a way to create a menu, table, etc. in one file and automatically insert it in the same (or even different) areas of all pages automatically?  So, can I create, for example, a page with a table - and have that table appear on all other pages where I want it inserted?
    Likewise, when I change something in a menu, to have that same menu on all other pages (where it appears) to automatically update?
    Many thanks, David  (see www.aloe-vera.org for the website I'm talking about)

    All the pages using Server Side Includes must be .asp or .shtml files. "
    Partly true but not the whole story.
    Your pages must have a file extension which tells the server to parse (or check) the code for Includes (and process them) before delivering the page to the browser.
    This file extension can be .php, .shtml, .asp or several others.
    Another alternative is to ask your web host to configure the server to check .html files for Includes too. Some hosts do this cheerfully. Others refuse.
    A longer term view is for you to plan for the future.
    If you accept the fact that, as your skills improve, you're likely to add more functionality to your website than simply SSIs. e.g. shopping cart, online forms, surveys, then you can prepare your site for the future by changing all your pages to a .php file extension now (or whatever your server language may be).
    This is a pain but means you have nothing furrther to do to improve the functionality of your website other than add code.
    Once all .html pages have been switched to .php you can add re-directs on the server so that SE results remain valid until your .php pages get indexed.
    Plenty of people come to this crossroads eventually. None regret biting the bullet and converting their pages.

  • If you have the iPhone 4s and you buy the iwork...later when you change your phone to iPhone 5 with the same app name and code the iwork still free to download into your new phone???

    if you have the 4s and you buy the iwork...later when you change your phone to 5 with the same app name and code the iwork still free to download into your new phone???

    Yes as long as you use the same Apple ID for iTunes that you used to download the app originally.
    Hope that helps

  • I have 2 i4 phones.  I can sign on to iCloud on 1 but never on the other.  Does anyone have the answer to this.  I have tried to change my password but I still have the same problem.  I keep getting message "Verification Failed The request timed out"

    I upgraded to 2 -  i4 phones with 2 different phone numbers.  I can sign on to iCloud on 1 phone but never on the other.  I have changed my my password twice but no matter what I do, I still have the same problem.  I keep getting a message "Verification Failed The request timed out"  no matter how many times I try to sign on it always times out.  Before I upgraded to the i4, I had a i3GS and had the same exact problem.  Does anyone have any ideas???

    Firstly, go to http://iforgot.apple.com and sign in with the ID you use for iCloud. A new password will be sent to your associated email address.
    If that doesn't work, for example because it's going to an address you can't access, then you will have to contact Support. Go to https://expresslane.apple.com ; click 'See all products and services' at the bottom of the page. In the next page click 'More Products and Services, then 'Apple ID'. In the next page select 'Other Apple ID Topics' then 'Lost or forgotten Apple ID password' and click 'Continue'.

  • ITunes auto changed a bunch of albums to have the same name and art. Any easy fix?

    So iTunes randomly changed a bunch of albums to be The Frozen Borderline by Nico with the album art (the artist names and song names are still the same though). I was just curious is there an easy fix, or do I have to go through and fix it one-by-one manually? Here's a screenshot: http://i.imgur.com/n6hfCZg.jpg

    Please? I really need help on this.

  • File changes from more than one user at the same time

    Hi,
    two of  my colleauges opened a photoshop file at the same time and both could make changes. Saving the file kills one person's changes, which actually shouldn't be possible. How can this be avoided?
    Thank you
    FriedaLee

    This is the boilerplate text often used in connection to saving to a network (please NOTE the part where it explains that normally, it does work, but that it is impossible to troubleshoot someone else's network remotely, and that's why it's not supported by Adobe):
    If you are opening files over a network or saving them to a network server, please cease and desist immediately in the event you are currently experiencing problems with one or more files. Working across a network is not supported.
    See: 
    http://kb2.adobe.com/cps/406/kb406793.html
      Copy the CLOSED file from your server to your local hard disk, work on it, save it again to your local hard disk, close it, and copy the closed file back to the server.
         Of course, the fact that Adobe does not support working across a network does not necessarily mean it won't work.   It should.
        Adobe's position is that there are too many variables in a network environment for them to guarantee that everything will work correctly in every network, especially given the fact that if something does not work properly, it's probably the network's fault, and Adobe has no way of troubleshooting your network.
      If you can't work locally, you are on your own, and if something happens, you're on your own. If you must work from a server, make sure your network administrator is a competent professional.
    When problems arise, a lot of valuable work can be lost.

Maybe you are looking for

  • Finally made the purchase!!!

    Well, I finally did it. I'm probably going to be sorry when they release a new imac next month, but I just couldn't wait any longer. Yesterday I ordered a new 20" imac 2GB of ram and the upgraded video card. Am I going to be sorry? I was wondering if

  • IPod touch wheel and iPod software version 1.5

    Hi, I have a problem with my iPod touch wheel (20 GB). I have purchased some music on the iTMS this days, but i was unable to transfer it to my Ipod, which software version was 1.4. So, I decide to restore the iPod with the latest version for this mo

  • Data Manager lock

    Could someone tell me what message you get when you attempt to run a package on locked data. I am testing data locking. It works fine when i try to submit data through an input schedule. But for some reason I am able to run a DM package on locked dat

  • Prime Infrastructure 1.1 software

    Hi Experts, I am working in a project needs Cisco prime infrastructure and the sales department already bought v1.1 R-PI-1.1-100-K9, but I don't have the CD for software, how can I get the software for this version 1.1. Thanks Mohammad Saeed

  • Latest Flash Player For Windows 8 x86 - link broken?

    Hi all, Is it my imagination or is the download link broken from W8 x86? The webpage is here: http://support.microsoft.com/kb/2880289 But when you click on the the link for W8: http://www.microsoft.com/downloads/details.aspx?FamilyId=711cb843-123e-4b