Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Microsoft Dataverse
Answered

Set OptionSetvalue with PowerShell Set-CRMRecord

(0) ShareShare
ReportReport
Posted on 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 😃

 

  • Verified answer
    TheMichael Profile Picture
    13 on at
    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 at
    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,166 Super User 2025 Season 1 on at
    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Microsoft Dataverse

#1
mmbr1606 Profile Picture

mmbr1606 22 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 17

#3
ankit_singhal Profile Picture

ankit_singhal 11 Super User 2025 Season 1

Overall leaderboard

Featured topics