[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


PSScript-Copy First 3 Char of Attribute 2 Attribute

Posted on 2014-08-15
Medium Priority
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
  • 2
  • 2
LVL 40

Expert Comment

ID: 40263725
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

ID: 40264037
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

Subsun earned 2000 total points
ID: 40264054
Do you need to keep existing values for extensionAttribute13? if not, in code replace -Add with -Replace

Author Closing Comment

ID: 40268671
Does what I needed.   Thank you very much!

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
Screencast - Getting to Know the Pipeline

868 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