How to Invoke Scripts Within a Cmdlet
This example shows how to invoke a script that is supplied to a cmdlet. The script is executed by the cmdlet, and its results are returned to the cmdlet as a collection of System.Management.Automation.PSObject objects.
To invoke a script block
The command verifies that a script block was supplied to the cmdlet. If a script block was supplied, the command invokes the script block with its required parameters.
if (script != null) { WriteDebug("Executing script block."); // Invoke the script block with the required arguments. Collection<PSObject> PSObjects = script.Invoke( line, simpleMatch, caseSensitive ); // more code as needed... }
Then, the script iterates through the returned collection of System.Management.Automation.PSObject objects and perform the necessary operations.
foreach (PSObject object in PSObjects) { if (LanguagePrimitives.IsTrue(object)) { result = new MatchInfo(); result.Line = line; result.IgnoreCase = !caseSensitive; break; } }
See Also
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
PowerShell