0

I'm trying to find a way to replace a column which contains my email address by a person column So I write a small script to do that but it doesn't work:

$list = $SiteURL.Lists.TryGetList($ListName)
$items = $list.items

foreach($item in $items)
{
    $user = $item["Email Address"]
    $Values=  get-aduser -filter {mail -eq 'myuser@emailaddress.com'}
    $item["toto"] =  $Values.SamAccountName
    $item.Update()
}

but when I run my script; I get the following error message:

Exception calling "Update" with "0" argument(s): "Invalid data has been used to update the list item. The field you are trying to update may be read only."

I printed my Values.SamAccountName on my screen and the showed value is corrected

any idea of what I'm doing wrong?

0

What’s the type of "Email Address" column and "toto" column?

If they are not the same type of columns, you cannot replace value with each other. And make sure you have permission to edit the list.

  • Email adress is a text and toto is User I used the get-aduser - filter line, to transform my text to user (toto contains email adress of my user) – freedumz Sep 6 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.