0

I installed Sitecore Powershell extension 5.1 on my sitecore 9.0.2 which is in azure PaaS. The imported SPE remoting module 5.1 to my windows powershell(5.1) on my local machine. I enabled remoting in config and allow the role sitecore\IsAdministrator. Now I run the following script from my windows powershell ISE

$session = New-ScriptSession -Username admin -Password b -ConnectionUri https://********-cm.azurewebsites.net

Invoke-RemoteScript -Session $session -ScriptBlock { Write-Host "Hi" }

Stop-ScriptSession -Session $session

I get the following error

You cannot call a method on a null-valued expression.
At C:\Users\kchithiraisenan\Documents\WindowsPowerShell\Modules\SPE\Invoke-RemoteScript.ps1:344 char:21
+                     $taskResult.Content.ReadAsStringAsync().Result
+                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

How can I fix this?

  • Can you try without having the Write-Host. You may try -ScriptBlock { "Hi" } or -ScriptBlock { Get-Item "master:\sitecore\content\Home" -Language "en" } and see if you have the same error – Hishaam Namooya Jun 5 at 20:17
  • That did not work. But I found the issue. New-WebServiceProxy cmdlet did not create an object and was throwing error internally that the 'Underlying connection was closed unexpectedly' Then i added [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 before the callinf New-WebServiceProxy cmdlet and now everything works just fine. – Komahan Jun 6 at 17:25
0

New-WebServiceProxy cmdlet did not create an object and was throwing error internally that the 'Underlying connection was closed unexpectedly' Then adding the follwing line [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 before the calling New-WebServiceProxy cmdlet fixed it.

New-WebServiceProxy cmdlet is used in Invoke-RemoteScript.ps1 file

| improve this answer | |

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.