web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : 976mYAINun+6KexPUE6Vez
Power Apps - Microsoft Dataverse
Answered

Set OptionSetvalue with PowerShell Set-CRMRecord

Like (0) ShareShare
ReportReport
Posted on 28 Mar 2024 11:31:09 by 13

Hello,

I have a table ehg_virtualserver with the OptionSet column ehg_osupdatebehaviour and I would like to use Set-CrmRecord CMDlet to set the value, something like this:

 

 

Set-CrmRecord ehg_virtualserver -Id $recordid -Fields @{"ehg_osupdatebehaviour" = "Manual Triggered"}

 

 

but I get an error "Incorrect attribute value type System.String", same happens with an Integer error when I try to use the value 786120000 of the option set instead of the label. Any help on how to set an option set value would be appreciated 😃

 

I have the same question (0)
  • Verified answer
    TheMichael Profile Picture
    13 on 28 Mar 2024 at 14:55:53
    Re: Set OptionSetvalue with PowerShell Set-CRMRecord

    Hi, I found the solution with the help of a consultant. The problem was I ran the script with PowerShell Core. In PowerShell Desktop I was able to pass the OptionSetObject. Looks like this:

    $optionSetValue = New-Object -TypeName Microsoft.Xrm.Sdk.OptionSetValue -ArgumentList 786120000
    Set-CrmRecord -EntityLogicalName ehg_virtualserver -Id "39981cc2-83ea-ed11-8849-000d3ab699fb" -Fields @{"ehg_osupdatebehaviour" = $optionSetValue}
  • TheMichael Profile Picture
    13 on 28 Mar 2024 at 12:54:16
    Re: Set OptionSetvalue with PowerShell Set-CRMRecord

    Hi Rampprakash,

    thanks for the fast reply! 

    I tried

     

    $entity = Get-CrmRecord -EntityLogicalName "ehg_virtualserver" -Id "39981cc2-83ea-ed11-8849-000d3ab699fb" -Fields ehg_name,ehg_osupdatebehaviour
    $entity.Attributes["ehg_osupdatebehaviour"] = "Manual Triggered"

     

    but then I get the error "InvalidOperation: Cannot index into a null array." Same happens when I try the value instead of the optionset label. 

     

    Edit: When I try to access the property with a dot and set the record like this:

    $entity.ehg_osupdatebehaviour = "Manual Triggered"
    Set-CrmRecord -Entity $entity -Id "39981cc2-83ea-ed11-8849-000d3ab699fb" -Fields ehg_osupdatebehaviour

    I get the error that, “The argument transformation for the parameter “Fields” cannot be processed. The value “ehg_osupdatebehaviour” of type “System.String” cannot be converted to the type “System.Collections.Hashtable”.

  • Ram Prakash Profile Picture
    5,450 Super User 2025 Season 2 on 28 Mar 2024 at 12:32:37
    Re: Set OptionSetvalue with PowerShell Set-CRMRecord

    Hi @TheMichael 

     

    Can you please try below PowerShell Script

     

    $entity = Get-CrmRecord -EntityLogicalName "<entity_name>" -Id "<record_id>"

    $entity.Attributes["<attribute_name>"] = $optionSetValue

    Set-CrmRecord -Entity $entity

     

    Please mark as Answer if it is helpful and provide Kudos


    Subscribe : https://www.youtube.com/channel/UCnGNN3hdlKBOr6PXotskNLA
    Follow me on Twitter : @rampprakashd
    Blog : https://microsoftcrmtechie.blogspot.com

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Tom Macfarlan – Community Spotlight

We are honored to recognize Tom Macfarlan as our Community Spotlight for October…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 752 Most Valuable Professional

#2
developerAJ Profile Picture

developerAJ 472

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 358 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics