'Running Powershell script in Jenkins Declarative pipeline

I want to run Powershell script on agent from Jenkins declarative pipeline. It hangs on the script execution step (click on Job logs) and i have to forcefully exit it. What is the correct way to execute powershell script from pipeline and also so that it show output in console. I have gone through many solutions but no success yet.

Some useful snippets:

Pipeline code

Job logs



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source