/// <summary> /// Execute one or more PowerShell script files to get language blocks. /// </summary> /// <param name="sources"></param> /// <returns></returns> private static IEnumerable <ILanguageBlock> GetLanguageBlock(RunspaceContext context, Source[] sources) { var results = new Collection <ILanguageBlock>(); var ps = context.GetPowerShell(); try { context.Writer.EnterScope("[Discovery.Rule]"); PipelineContext.CurrentThread.ExecutionScope = ExecutionScope.Script; // Process scripts foreach (var source in sources) { foreach (var file in source.File) { if (file.Type != RuleSourceType.Script) { continue; } ps.Commands.Clear(); context.VerboseRuleDiscovery(path: file.Path); context.EnterSourceScope(source: file); var scriptAst = System.Management.Automation.Language.Parser.ParseFile(file.Path, out Token[] tokens, out ParseError[] errors);
private PowerShell GetCondition(RunspaceContext context) { var result = context.GetPowerShell(); result.AddCommand(new CmdletInfo(InvokeBlockCmdletName, typeof(InvokeRuleBlockCommand))); result.AddParameter(InvokeBlockCmdlet_TypeParameter, Type); result.AddParameter(InvokeBlockCmdlet_IfParameter, If); result.AddParameter(InvokeBlockCmdlet_BodyParameter, Body); return(result); }