Hello everyone, I have been tasked with the following and struggle with scripting still.<\/p>\n
Goal: Create a script that will take the contents from the “office” field in AD and apply them to first name / last name. The first name is always going to be “store” for this particular script. The lase name will be the store #. The goal is to have it universally the same naming convention.<\/p>\n
Ex. Office field displays Store 32.<\/p>\n
I am needing to have Store in the first name field and the store # in last name field. There are about 300 entries so I was hoping to be able to copy the first word in the office field to first name and the second one being the number to the last name field.<\/p>","upvoteCount":8,"answerCount":16,"datePublished":"2023-07-31T16:54:55.000Z","author":{"@type":"Person","name":"spiceuser-icda7","url":"https://community.spiceworks.com/u/spiceuser-icda7"},"acceptedAnswer":{"@type":"Answer","text":"
something like this is the theory (assuming your office attribute is literally just the store and the ID “Store 123”<\/p>\n
$ADUsers= \nGet-aduser -Filter * -searchbase \"OU=Users,OU=HQ,DC=Contoso,DC=com\" -Properties office\n\nforeach($userObject in $ADUsers){\n $store,$storeNumber = $userObject.office -split \"\\s\"\n\n Set-ADUser $userObject -GivenName $store -Surname $storeNumber\n}\n<\/code><\/pre>\n
This is literally just updating the First and GivenName, if you need Displayname, Name, etc there is more to do, but gives you the idea.<\/p>\n
This is code from the internet, always TEST THE CODE THOUROUGHLY and DO NOT run it in PRODUCTION.<\/strong>
\nRun it against a single test user first and see what it does<\/p>","upvoteCount":3,"datePublished":"2023-07-31T17:31:02.000Z","url":"https://community.spiceworks.com/t/need-some-scripting-help/956448/7","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"Hello everyone, I have been tasked with the following and struggle with scripting still.<\/p>\n
Goal: Create a script that will take the contents from the “office” field in AD and apply them to first name / last name. The first name is always going to be “store” for this particular script. The lase name will be the store #. The goal is to have it universally the same naming convention.<\/p>\n
Ex. Office field displays Store 32.<\/p>\n
I am needing to have Store in the first name field and the store # in last name field. There are about 300 entries so I was hoping to be able to copy the first word in the office field to first name and the second one being the number to the last name field.<\/p>","upvoteCount":8,"datePublished":"2023-07-31T16:54:55.000Z","url":"https://community.spiceworks.com/t/need-some-scripting-help/956448/1","author":{"@type":"Person","name":"spiceuser-icda7","url":"https://community.spiceworks.com/u/spiceuser-icda7"}},{"@type":"Answer","text":"