Issue running a post powershell script

Used to work on server 2016 but doesnt work on server 2019. What could be the issue?

2020-02-01 22:12:22.521 -05:00 [INF] Post-Request Script output:
Error - CmdletInvocationException: Object reference not set to an instance of an object.
at System.Management.Automation.Runspaces.AsyncResult.EndInvoke()
at System.Management.Automation.PowerShell.EndInvoke(IAsyncResult asyncResult)
at Certify.Management.PowerShellManager.<>c__DisplayClass0_1.b__5() in C:\Work\GIT\certify\src\Certify.Shared\Management\PowerShellManager.cs:line 86
at System.Threading.Tasks.Task.Execute()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Certify.Management.PowerShellManager.d__0.MoveNext() in C:\Work\GIT\certify\src\Certify.Shared\Management\PowerShellManager.cs:line 95

Hi, the error is happening inside your powershell script. Here is a test script for you to try on the same server which logs to C:\temp\ps-test.txt (for example):

$logpath = "c:\temp\ps-test.txt"

$date = Get-Date

Add-Content $logpath ("-------------------------------------------------");
Add-Content $logpath ("Script Run Date: " + $date)
Add-Content $logpath ($result | ConvertTo-Json)

Please keep in mind that when your script runs during certificate renewal, it does so as Local System, not as your user account, so if your script depends on your permissions (or environment variables) then you need to consider other approaches.

Some people prefer to write the required output (such as the latest certificate thumbprint value) to a text file then use that in another script (perhaps run manually during a maintenance window or as a scheduled task), that way you can also debug interactively while developing your script in Powershell ISE etc

Here is my script:

Any help is appreciated, thanks!