Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Jedes Windows PowerShell Modul oder Cmdlet kann mithilfe der Methoden der Microsoft.Powershell.Activitygenerator-Klasse als Workflowaktivität verpackt werden. Verwenden Sie die Methoden Microsoft.Powershell.Activitygenerator.Generatefrommoduleinfo*, Microsoft.Powershell.Activitygenerator.Generatefromcommandinfo*, und Microsoft.Powershell.Activitygenerator.Generatefromname* -Methoden der Microsoft.Powershell.Activitygenerator-Klasse , um C#-Code zu generieren, der eine Aktivität darstellt. Anschließend können Sie den resultierenden C#-Code in eine Assembly kompilieren, die einem Projekt als Aktivität hinzugefügt werden kann.
Anschließend können Sie den resultierenden C#-Code in eine Assembly kompilieren, die einem Projekt als Aktivität hinzugefügt werden kann, indem Sie eine Befehlszeile mit dem folgenden Formular verwenden.
csc /nologo /out:AssemblyName /target:library /reference:System.Activities.Activity /reference:Microsoft.PowerShell.Activities codefile.cs
Beispiel 1
Im folgenden Beispiel wird veranschaulicht, wie C#-Code für eine Aktivität aus einem Windows PowerShell Modul generiert wird.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Management.Automation;
using System.Collections.ObjectModel;
using Microsoft.PowerShell.Activities;
namespace MakeActivity
{
class Program
{
static void Main(string[] args)
{
StreamWriter CodeFile = new StreamWriter("c:\\\\testmodule\\codefile.cs");
Collection<PSModuleInfo> ModuleInfos = new Collection<PSModuleInfo> { };
PSModuleInfo ModuleInfo;
string ActivityCode = "";
string ModulePath = "";
Console.Write("Type the full path and filename of the module to process:");
ModulePath = Console.ReadLine();
PowerShell ps = PowerShell.Create();
ps.AddCommand("Import-Module").AddArgument(ModulePath);
ps.AddParameter("PassThru");
ModuleInfos = ps.Invoke<PSModuleInfo>();
ModuleInfo = (PSModuleInfo)ModuleInfos[0];
ActivityCode = ActivityGenerator.GenerateFromModuleInfo(ModuleInfo, "MyNamespace").First<String>();
CodeFile.Write(ActivityCode);
Console.ReadLine();
}
}
}
Beispiel 2
Im folgenden Beispiel wird veranschaulicht, wie C#-Code für eine Aktivität aus einem Windows PowerShell-Cmdlet generiert wird.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Management.Automation;
using System.Collections.ObjectModel;
using Microsoft.PowerShell.Activities;
namespace MakeActivity
{
class Program
{
static void Main(string[] args)
{
StreamWriter CodeFile = new StreamWriter("c:\\\\testmodule\\codefile.cs");
Collection<PSModuleInfo> ModuleInfos = new Collection<PSModuleInfo> { };
PSModuleInfo ModuleInfo;
Collection<CommandInfo> CommandInfos = new Collection<CommandInfo> { };
CommandInfo MyCommand;
string ActivityCode = "";
string ModulePath = "";
Console.Write("Type the full path and filename of the module to process:");
ModulePath = Console.ReadLine();
PowerShell ps = PowerShell.Create();
ps.AddCommand("Import-Module").AddArgument(ModulePath);
ps.AddParameter("PassThru");
ModuleInfos = ps.Invoke<PSModuleInfo>();
ModuleInfo = (PSModuleInfo)ModuleInfos[0];
ps.AddCommand("Get-Command").AddArgument(ModuleInfo);
CommandInfos = ps.Invoke<CommandInfo>();
MyCommand = CommandInfos[0];
ActivityCode = ActivityGenerator.GenerateFromCommandInfo(MyCommand, "MyNamespace");
CodeFile.Write(ActivityCode);
Console.ReadLine();
}
}
}