2

I am trying to get a media item using the below, most of the times it works perfectly fine for me, however sometimes the same Powershell returns [PSCustomObject], instead of the media item.

enter image description here

Sometimes it returns me the correct item and sometimes it returns me this Object which ultimately results in null item path. Please suggest here.

3
  • Is it possible that the item does not exist but SPE is just showing [PSCustomObject] instead of null? Commented Jul 1, 2020 at 17:21
  • I am having the same doubt, can anyone please suggest on this. Every time I get [PSCustomObject] I believe its not null, please suggest if my assumption is wrong here. Commented Jul 1, 2020 at 17:26
  • 2
    You could try if($GetImage -eq $null { Write-Host "It's null!" } Commented Jul 1, 2020 at 17:49

1 Answer 1

1

As Michael said in its comment, the item may be null. I did a quick test locally and below is the result

I've used the Item Id of the default Home item and the result shows that the item is not null.

$item = Get-Item -Path master -ID "{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"

if($item -ne $null){
    Write-Host "Item is not null"
}
else{
    
    Write-Host "Item null"
}

However, when I change the ID to something which does not exist, the result is still shown as PSCustomObject but it shows that the item is null.

So, you need to check for null on the variable $GetImage.

$GetImage= Get-Item -Path master: -ID $parsedID

if($GetImage -ne $null){
    # Process item here
}
else{
    Write-Host "Skipping item id $parsedID as it is null"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.