gpt4 book ai didi

powershell - 如何使用从cmdlet生成的Windows工作流事件?

转载 作者:行者123 更新时间:2023-12-03 00:19:00 27 4
gpt4 key购买 nike

我使用PowerShell 3.0从cmdlet生成了WWF Activity 。

 /// <summary>
/// Activity to invoke the Microsoft.Ceres.HostController.Cmdlets\Connect-Host command in a Workflow.
/// </summary>
[System.CodeDom.Compiler.GeneratedCode("Microsoft.PowerShell.Activities.ActivityGenerator.GenerateFromName", "3.0")]
public sealed class ConnectHost : PSRemotingActivity
{
/// <summary>
/// Gets the display name of the command invoked by this activity.
/// </summary>
public ConnectHost()
{
this.DisplayName = "Connect-Host";
}

/// <summary>
/// Gets the fully qualified name of the command invoked by this activity.
/// </summary>
public override string PSCommandName
{
get { return "Microsoft.Ceres.HostController.Cmdlets\\Connect-Host"; }
}

// Arguments

/// <summary>
/// Provides access to the Host parameter.
/// </summary>
[ParameterSpecificCategory]
[DefaultValue(null)]
public InArgument<System.String> Host { get; set; }

/// <summary>
/// Provides access to the Port parameter.
/// </summary>
[ParameterSpecificCategory]
[DefaultValue(null)]
public InArgument<System.String> Port { get; set; }

/// <summary>
/// Provides access to the NoConnectionSecurity parameter.
/// </summary>
[ParameterSpecificCategory]
[DefaultValue(null)]
public InArgument<System.Management.Automation.SwitchParameter> NoConnectionSecurity { get; set; }

/// <summary>
/// Provides access to the ServiceIdentity parameter.
/// </summary>
[ParameterSpecificCategory]
[DefaultValue(null)]
public InArgument<System.String> ServiceIdentity { get; set; }


// Module defining this command


// Optional custom code for this activity


/// <summary>
/// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
/// </summary>
/// <param name="context">The NativeActivityContext for the currently running activity.</param>
/// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
/// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
{
System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create();
System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

// Initialize the arguments

if (Host.Expression != null)
{
targetCommand.AddParameter("Host", Host.Get(context));
}

if (Port.Expression != null)
{
targetCommand.AddParameter("Port", Port.Get(context));
}

if (NoConnectionSecurity.Expression != null)
{
targetCommand.AddParameter("NoConnectionSecurity", NoConnectionSecurity.Get(context));
}

if (ServiceIdentity.Expression != null)
{
targetCommand.AddParameter("ServiceIdentity", ServiceIdentity.Get(context));
}

var cont = new ActivityImplementationContext() {PowerShellInstance = invoker};
return cont;
}
}

创建activity1.xaml之后,放入“Connect-Host” Activity 并编写开始代码:
var workflow1 = new Activity1();
WorkflowInvoker.Invoke(workflow1);

但我收到异常消息:
“'Microsoft.PowerShell.Workflow.ActivityHostProcess'的类型初始值设定项引发了异常。” “找不到路径'C:\ Windows \ system32 \ windowspowershell \ v1.0 \ modules \ psworkflow \ PSWorkflow.types.ps1xml的一部分。”

但是这个文件存在于我的系统中。

我如何使用这项技术?

最佳答案

这可能是Windows Powershell的问题。

解决方案是从"C:\Windows\System32\WindowsPowerShell\v1.0\Modules\"复制文件夹:“PSWorkflow”

"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules"
然后一切正常。

关于powershell - 如何使用从cmdlet生成的Windows工作流事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22405932/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com