3

I have a C# method that generates powershell scripts.

Is there a way to automatically validate the syntax of the generated scripts directly in C# before running them on the end client?

1
  • 2
    Why is this closed? Please vote to reopen, it's a valid question, on topic and in scope. One way would be to unit test them. Commented Jul 14, 2020 at 1:51

1 Answer 1

1

You could possibly use the Parser.ParseFile method from the PowerShell SDK, which might be found in the Microsoft.PowerShell.SDK nuget

Note : I have never used this and is totally untested, and truthfully i have no idea whether this will work for you.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I will give it a try and leave feedback.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.