Solved

Active Directory PS script to modify attributes from CSV file

Posted on 2013-12-17
4
3,373 Views
Last Modified: 2013-12-17
Hello PS - Experts,

I need help with a seemingly simple Powershell script.

I have a CSV looking like this:
Name,Uid,Gid
jsmith,123456,78910
user2,123457,78910

Open in new window


The script should read the values and select an AD object by logon name and modifying this object's attributes GIDnumber and UIDnumber values with the ones from the CSV.

Thanks in advance!
Helge
0
Comment
Question by:Daniel Helgenberger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 53

Expert Comment

by:Will Szymkowski
ID: 39724162
What attributes are you looking to change in Active Directory referencing GIDNumber and UIDNumber? Do you want these numbers in the extensionAttribute section for Users Accounts?

Below is the structure of how you can do this. I will still need to know what values you want to modify in AD using the GID/UID columns in your CSV file.

Import-module activedirectory
$ModUsers = import-csv "c:\yourCSVfile.csv"
foreach ($User in $ModUsers) {
$User.Name
$User.Uid
$User.Gid
Set-ADUser -Identity $User.Name -extensionAttribute1 $$User.Uid -extensionAttribute2 $User.Gid
}

Open in new window


Will
0
 
LVL 40

Accepted Solution

by:
footech earned 500 total points
ID: 39724185
Here's what I was thinking...
Import-Csv file.csv | ForEach `
{
    $uid = $_.UID
    $gid = $_.GID
    Get-ADUser $_.name | Set-ADUser -replace @{gidnumber=$gid;uidnumber=$uid}
}

Open in new window

0
 
LVL 13

Author Closing Comment

by:Daniel Helgenberger
ID: 39724265
Perfect, footech. Thanks!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

690 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