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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Set OptionSetvalue wit...
Power Apps
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 😃

 

I have the same question (0)
  • Ram Prakash Duraisamy Profile Picture
    5,714 Super User 2026 Season 1 on at

    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

  • TheMichael Profile Picture
    13 on at

    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”.

  • Verified answer
    TheMichael Profile Picture
    13 on at

    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}

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 493 Most Valuable Professional

#2
11manish Profile Picture

11manish 479

#3
Haque Profile Picture

Haque 328

Last 30 days Overall leaderboard