// 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 System.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 (SourceIdentifier.Expression != null) { targetCommand.AddParameter("SourceIdentifier", SourceIdentifier.Get(context)); } if (SubscriptionId.Expression != null) { targetCommand.AddParameter("SubscriptionId", SubscriptionId.Get(context)); } if (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
protected override void Execute(CodeActivityContext context) { try { var azureVM = new AzureVMTerminalRunner(SubscriptionId.Get(context), ClientSecret.Get(context) , ClientId.Get(context), TenantId.Get(context)); var resonses = azureVM.RunUnixCommand(GroupName.Get(context), VmName.Get(context), Commands.Get(context).Split(';'), VmUserName.Get(context) , VmUserPassword.Get(context)); Response.Set(context, JsonConvert.SerializeObject(resonses)); } catch (Exception e) { Error.Set(context, e.Message); } }
protected override void Execute(CodeActivityContext context) { try { var azureVM = new AzureVM(SubscriptionId.Get(context), ClientSecret.Get(context) , ClientId.Get(context), TenantId.Get(context)); azureVM.CreateCentOS7VM(GroupName.Get(context), VmName.Get(context), Region.Get(context), VmUserName.Get(context) , VmUserPassword.Get(context)); Response.Set(context, "Complete"); } catch (Exception e) { Error.Set(context, e.Message); } }