2

I was trying to get media item using media ID. I am getting the below error which I haven't faced before in powershell sitecore.

Scenario

$ImageId - {61630AC1F0E3111B9C50CEEE0B2B0223}

I am using the below command and getting below mentioned error:-

Get-Item -Path master: -ID $ImageId

Error

Get-Item : Expected hex 0x in '{0}'. Actual value: {61630AC1F0E3111B9C50CEEE0B2B0223}

The same command is working fine in 2 more places, is this a PowerShell extension bug ?

  • For me the same command is working fine and returning results. COuld you check with any other image? $ImageId = "{F2CE0A45-0187-4E36-8AEF-1185C1B74FAA}" Get-Item -Path master: -ID $ImageId – Sreekrishnan Jun 30 at 8:06
  • $item = Get-Item -Path "master:{path}" -Id "{6AA5AA9F-071A-4808-91AC-709FAAFFB310}" $mediaItem = [Sitecore.Data.Items.MediaItem]$item Does this help? – Paulson Maclean Jun 30 at 8:20
  • I believe I was not able to explain the context properly, apologies. Firstly the ID which I am getting is {61630AC1F0E3111B9C50CEEE0B2B0223} which is not in a valid format. Can I parse this ID to SItecore GUID format using powershell, the rest will work fine I believe. – Divyansh Gupta Jun 30 at 8:27
  • yes, correct.. now I understand your question. Did you try something like this : $parsedID = [Sitecore.Data.ID]$ImageId? – Paulson Maclean Jun 30 at 8:42
  • I tried just now with this, it gives me this error :- Cannot convert value "{61630AC1F0E3111B9C50CEEE0B2B0223}" to type "Sitecore.Data.ID". Error: "Expected hex 0x in '{0}'. Actual value: {61630AC1F0E3111B9C50CEEE0B2B0223}" – Divyansh Gupta Jun 30 at 8:48
2

The first issue is because the ID that you are trying to use is not in the proper format. One way to workaround this is to parse the id that you received without the { }. Please see code below

$id = [Sitecore.Data.ID]::Parse("110D559FDEA542EA9C1C8A5DF7E70EF9")
$item = Get-Item "master: -ID $id"
$item

The above code snippet will provide the below output

enter image description here

So, for your case, all you need to do at first is to remove the { } and then parse the value to the ID.Parse method.

Update

Below is a script snippet on replacing the { }

$ImageStringId = "{61630AC1F0E3111B9C50CEEE0B2B0223}"

$updatedStringId = $ImageStringId.replace("{","")
$updatedStringId = $updatedStringId.replace("}","")

Write-Host "Updated Image String Id $updatedStringId"

$id = [Sitecore.Data.ID]::Parse($updatedStringId)

$item = Get-Item "master: -ID $id"
$item
| improve this answer | |
  • 1
    Nice! $x needs to be changed to $id in line #2 I guess.. – Paulson Maclean Jun 30 at 9:02
  • @PaulsonMaclean correct. Just updated the answer – Hishaam Namooya Jun 30 at 9:03
  • I tried with this just now, its also giving me this below error :- Exception calling "Parse" with "1" argument(s): "Expected hex 0x in '{0}'. Actual value: {61630AC1F0E3111B9C50CEEE0B2B0223} – Divyansh Gupta Jun 30 at 9:03
  • @DivyanshGupta you need to remove the starting { and ending } – Hishaam Namooya Jun 30 at 9:05
  • Thanks for correcting me, this works perfectly fine for me, Thank you for providing the solution. :) – Divyansh Gupta Jun 30 at 9:07

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.