1

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 Files\WindowsPowerShell\Modules\SPE\6.0.0\Invoke-RemoteScript.ps1:344 char:21 + $taskResult.Content.ReadAsStringAsync().Result + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

How can I fix it?

4
  • What version of Sitecore PowerShell Extensions do you have installed in your instance? Feb 17 '20 at 5:05
  • @MichaelWest 6.0.0, Sitecore, if that matters, is 9.2 xp0 topology
    – JleruOHeP
    Feb 17 '20 at 5:06
  • Did you enable the remoting service using a patch? Feb 17 '20 at 5:27
  • @MichaelWest no, will try to find a patch and apply it. Thanks for the suggestion
    – JleruOHeP
    Feb 17 '20 at 5:36
0

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
2
  • Thank you! Tried it, but still the same error. And if I try to just $session I can see the object with all the correct properties (and values). Only empty value on $session is Credential. But Password and Username are there
    – JleruOHeP
    Feb 17 '20 at 4:58
  • Tried the example with an extra line of $credential = Get-Credential and passing it to -Credential $credential. Same result...
    – JleruOHeP
    Feb 17 '20 at 5:05
0

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

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.