TransWikia.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!

Ask a Question

Get help from others!

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