How do I validate PowerShell script syntax in C#?

Viewed 137

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 Answers

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.

Related