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 😃
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}
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”.
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
mmbr1606
22
Super User 2025 Season 1
stampcoin
17
ankit_singhal
11
Super User 2025 Season 1