The psd1 file is a valid PowerShell script, so itβs best to allow PowerShell to parse the file.
The easiest way is to use the Test-ModuleManifest cmdlet. From C #, it looks something like this:
using (var ps = PowerShell.Create()) { ps.AddCommand("Test-ModuleManifest").AddParameter("Path", manifestPath); var result = ps.Invoke(); PSModuleInfo moduleInfo = result[0].BaseObject as PSModuleInfo;
Other approaches cannot handle the complexities of PowerShell parsing, for example. it would be easy to handle comments incorrectly or here lines when trying to use a regular expression.
source share