PSScript-Copy First 3 Char of Attribute 2 Attribute

Posted on 2014-08-15
Last Modified: 2014-08-18
I need a Powershell script that will copy the first 3 characters of one AD attribute (Office Field / physicalDeliveryOfficeName) to another AD attribute (Custom Attribute13 / extensionattribute13) that can be run against all AD accounts in org (or all AD accounts that have office field populated)
Question by:itsystemsoperations
    LVL 40

    Expert Comment

    Following code should do it..
    Import-Module Activedirectory
    Get-ADuser -f * -Pr Office |?{$_.Office} |%{Set-ADUser $_.DistinguishedName -Add @{extensionAttribute13=$($_.Office.substring(0,3))}}

    Open in new window


    Author Comment

    I got an error when running that:

    Set-ADUser : Multiple values were specified for an attribute that can have only one value:2 char:55

    + FullyQualifiedErrorId : Multiple values were specified for an attribute that can have only one value,Microsoft.ActiveDirectory.Management.Commands.SetADUser
    LVL 40

    Accepted Solution

    Do you need to keep existing values for extensionAttribute13? if not, in code replace -Add with -Replace

    Author Closing Comment

    Does what I needed.   Thank you very much!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
    How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    745 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now