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

x
?
Solved

PSScript-Copy First 3 Char of Attribute 2 Attribute

Posted on 2014-08-15
4
Medium Priority
?
162 Views
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)
0
Comment
Question by:itsystemsoperations
  • 2
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Subsun
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

0
 

Author Comment

by:itsystemsoperations
ID: 40264037
Subsun:
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
0
 
LVL 40

Accepted Solution

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

Author Closing Comment

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

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