Fjärilsmannen
Fjärilsmannen
CC#
Created by Fjärilsmannen on 6/24/2023 in #help
❔ C# Powershell, pipe one script to another?
Is it possible to run a script and pipe that result to another? The closest I find is something like this:
System.Management.Automation.PSDataCollection<System.Management.Automation.PSObject> res = null;
foreach (var item in this.tasks)
{
Console.WriteLine($"Executing script: {scripts[item.script].path}");
// add current script and parameters
ps.AddScript(scripts[item.script].script, true).AddParameters(item.parameters);
// check if we got a previous result
if (res is not null)
{
// check if the result has anything in it
if (res.Count > 0)
{
// add the previous result as an argument for the current script
// this seems to add the result to the first parameter of the same type
ps.AddArgument(res[0]);
}
}

// Execute script
res = await ps.InvokeAsync();
}
System.Management.Automation.PSDataCollection<System.Management.Automation.PSObject> res = null;
foreach (var item in this.tasks)
{
Console.WriteLine($"Executing script: {scripts[item.script].path}");
// add current script and parameters
ps.AddScript(scripts[item.script].script, true).AddParameters(item.parameters);
// check if we got a previous result
if (res is not null)
{
// check if the result has anything in it
if (res.Count > 0)
{
// add the previous result as an argument for the current script
// this seems to add the result to the first parameter of the same type
ps.AddArgument(res[0]);
}
}

// Execute script
res = await ps.InvokeAsync();
}
8 replies
CC#
Created by Fjärilsmannen on 6/23/2023 in #help
How do you get the output type from a powershell script with System.Management.Automation?
I am trying to figure out how to get the type specified in a powershell script [OutputType([int])] for example. I can find it in the parsed attributes but it's just treated as an attribute that has "[int]", so it's not seen as a type but just the string value. But there seems to be a OutputTypeAttribute class, but i can't find any information on how to get a hold of that.
21 replies
CC#
Created by Fjärilsmannen on 6/11/2023 in #help
❔ Load Powershell Scripts as dynamic functions for a job manager?
Is it possible to use System.Management.Automation.PowerShell to load powershell scripts (where the script itself is just one big function), and then execute them as functions? I know you can just load a script and execute it at once, but i am trying to make a job manager where you got different scripts that you can assign work to. As a workflow, you create a task, then add inputs and available script/s to do what you want. But i can't figure out if it's possible to even load scripts and have them callable to begin with.
5 replies