AnswerBun.com

Sitecore Powershell Extension throws null-valued expression exception

Sitecore Asked by JleruOHeP on February 15, 2021

On a fresh Windows VM I installed powershell extensions module:

Install-Module SPE

Then I am trying to invoke a remote script on my sitecore instance:

$url = "https://my-sitecore.azurewebsites.net"
$session = New-ScriptSession -Username admin -Password b -ConnectionUri $url
Invoke-RemoteScript -Session $session -ScriptBlock { Write-Host "Foo" }

But it fails with

You cannot call a method on a null-valued expression. At C:Program
FilesWindowsPowerShellModulesSPE6.0.0Invoke-RemoteScript.ps1:344
char:21
+ $taskResult.Content.ReadAsStringAsync().Result
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

How can I fix it?

2 Answers

Apparently, the error was because of different versions of SPE installed locally and on the sitecore instance.

I used a sitecore vanila package with pre-installed SPE and a couple of extra packages and the SPE version was 5.0

Locally I used the latest - 6.0 and they are not backward compatible! But from the good news - SPE 5.0 works with sitecore 9.2

To solve the issue I had to downgrade installed SPE:

Remove-Package SPE
Uninstall-Package SPE
Install-Package -Name SPE -RequiredVersion 5.0

Answered by JleruOHeP on February 15, 2021

This type of error appears when you have an undeclared (null) variable. For me looks like $session is null .

Can you update your script in this way:

$session = New-ScriptSession -Username "admin" -Password "b" -ConnectionUri $url

Answered by Vlad Iobagiu on February 15, 2021

Add your own answers!

Related Questions

How to get General Link Field in RenderFieldArgs?

0  Asked on August 23, 2021 by gautam-aneja

 

Setting site default language in SXA

1  Asked on August 23, 2021 by mohamed-mosa

   

Sitecore domain and sub domain authentication

1  Asked on August 23, 2021 by suresh-r

   

No data recorded in Experience Analytics

3  Asked on August 23, 2021 by breno-diniz-pelosi

   

GraphQL query to search for pages based on template

2  Asked on August 23, 2021 by serhii-shushliapin

   

Sitecore SxA Composite Layout not adding custom css and js

1  Asked on August 23, 2021 by nadine-lendzian

 

Sitecore Item URL with Custom Domain in Azure PaaS

2  Asked on August 23, 2021 by alok-kumar

   

Updated field in rendering variant not working

2  Asked on August 23, 2021 by barada-behura

   

Creating multi site using Sitecore JSS

1  Asked on August 23, 2021 by haappyy02

 

Scale Out Content Management AppService

1  Asked on August 23, 2021 by pirate-briggs

     

Use SXA rendering variant for dynamic object

1  Asked on August 23, 2021 by user2980

   

Custom Item Url Builder

1  Asked on August 23, 2021 by ethan-schofer

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP