简体   繁体   中英

How do I validate PowerShell script syntax in C#?

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM