# Powershell script to edit users ADSI edit fields cant get it to work from CSV

**URL:** <https://forums.powershell.org/t/powershell-script-to-edit-users-adsi-edit-fields-cant-get-it-to-work-from-csv/4539>\
**Category:** PowerShell Help\
**Created:** [July 20, 2015, 11:47am UTC](https://forums.powershell.org/t/powershell-script-to-edit-users-adsi-edit-fields-cant-get-it-to-work-from-csv/4539 "2015-07-20T11:47:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![side-killer](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@side-killer](https://forums.powershell.org/u/side-killer)\
**Post date:** [July 20, 2015, 11:47am UTC](https://forums.powershell.org/t/powershell-script-to-edit-users-adsi-edit-fields-cant-get-it-to-work-from-csv/4539/1 "2015-07-20T11:47:26Z")

</div>

Here is what i have (the headers of the CSV file are “DistinguishedName” and “ObjectGUID”  
$csvData = import-csv C:\temp\user.csv

foreach ($row in $csvData)  
{  
$DN = $csvData.DistinguishedName  
$DN2 = “LDAP://”+$DN  
$GUID = $csvData.ObjectGUID

$User = [ADSI]“$DN2”  
$User.Put(“adminDescription”,$GUID)  
$User.SetInfo()

}

now if i replace my Variables with the details in my CSV file it works fine

it seems it might be an issue with how i am reading and using the CSV

any idea’s?

any help is very apreciated

---

<div class="post-metadata">

**Author:** ![max-kozlov](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@max-kozlov](https://forums.powershell.org/u/max-kozlov)\
**Post date:** [July 20, 2015, 3:28pm UTC](https://forums.powershell.org/t/powershell-script-to-edit-users-adsi-edit-fields-cant-get-it-to-work-from-csv/4539/2 "2015-07-20T15:28:04Z")

</div>

try to print $csvdata after importing it. do You have objects with multiple properties or just strings inside one property ?

take a look to **-delimiter** for import-csv cmdlet. may be your csv have ‘;’ as delimiter, but for your locale import-csv use ‘,’ as default or vice versa

---

<div class="post-metadata">

**Author:** ![side-killer](https://avatars.discourse-cdn.com/v4/letter/s/c6cbf5/32.png) [@side-killer](https://forums.powershell.org/u/side-killer)\
**Post date:** [July 20, 2015, 3:33pm UTC](https://forums.powershell.org/t/powershell-script-to-edit-users-adsi-edit-fields-cant-get-it-to-work-from-csv/4539/3 "2015-07-20T15:33:59Z")

</div>

It did have multiple properties , i ended up fixing it using just the Distinguished name and pulling the GUID in the command , bellow is what i ened up using had me racking the brain for a while

$csv=import-csv C:\temp\user.csv -Header DistinguishedName  
foreach ($line in $csv) {  
$DN = $line.DistinguishedName  
$GUID = [guid]((([directoryservices.directorysearcher] “(DistinguishedName=$DN)”).findall())[0].properties.getenumerator() | ? { $\_.name -eq “objectguid”}).value[0]  
$DN2 = “LDAP://”+$line.DistinguishedName  
$User = [ADSI]“$DN2”  
$User.Put(“adminDescription”, “$GUID”)  
$User.SetInfo()  
Write-Host $line.DistinguishedName  
Write-Host $DN2  
Write-Host $GUID  
}

---

<div class="post-metadata">

**Author:** ![max-kozlov](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@max-kozlov](https://forums.powershell.org/u/max-kozlov)\
**Post date:** [July 20, 2015, 11:08pm UTC](https://forums.powershell.org/t/powershell-script-to-edit-users-adsi-edit-fields-cant-get-it-to-work-from-csv/4539/4 "2015-07-20T23:08:32Z")

</div>

hmm, I was too fast…  
in your first example you write

foreach ($row in $csvData)  
` $DN = $csvData.DistinguishedName
$GUID = $csvData.ObjectGUID`

while it must be  
` $DN = $row.DistinguishedName
$GUID = $row.ObjectGUID`

Do you have any need in [adsi] in place of ActiveDirectory or Quest Active directory modules? these modules allow to manipulate directory objects much better and all process will be easy

`get-qaduser $username | %{ set-qaduser -objectattributes @{adminDescription=$.ObjectGuid} }`  
_or  
 `get-aduser $username | foreach-object { $`_`| Set-ADUser -Replace @{adminDescription=$_.objectguid} }`

and if you want low level without modules you can use  
`$userobj = [System.DirectoryServices.DirectoryEntry]'LDAP://$DN"
instead of [directorysearcher] and do direct property manipulation`

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [July 20, 2015, 11:16pm UTC](https://forums.powershell.org/t/powershell-script-to-edit-users-adsi-edit-fields-cant-get-it-to-work-from-csv/4539/5 "2015-07-20T23:16:34Z")

</div>

Glad you have things working, but just wanted to make a comment. It appears you have an AD dump to a CSV and then enumerate the CSV to set a property on the user. That’s a long path as you could have done something like this:

```
Get-ADUser -Filter * -Properties adminDescription | Set-ADUser -Add @{adminDescription=$_.ObjectGUID}
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:46pm UTC](https://forums.powershell.org/t/powershell-script-to-edit-users-adsi-edit-fields-cant-get-it-to-work-from-csv/4539/6 "2024-05-16T20:46:14Z")

</div>

Closed on May 16, 2024, 8:46pm UTC


