Skip to content

Commit

Permalink
Powershell Plugin Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewste committed Mar 17, 2013
1 parent 744dda2 commit 65c8c34
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
36 changes: 32 additions & 4 deletions Plugins/OSAE.PowerShellProcessor/PowerShellPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
{
using System;
using System.Collections.ObjectModel;
using System.Data;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;

/// <summary>
/// Allows OSA to run scripts through PowerShell.
/// </summary>
class PowerShellPlugin : OSAEPluginBase
{
/// <summary>
/// Provides access to the OSA logging functionality
/// </summary>
Logging logging = Logging.GetLogger("PowerShell Plugin");

/// <summary>
/// The plugin name
/// </summary>
string pName;

/// <summary>
Expand All @@ -31,12 +40,20 @@ public override void ProcessCommand(OSAEMethod method)
/// <param name="script">The script to be run</param>
private void RunScript(string script)
{
Pipeline pipeline = null;
Runspace runspace = null;

try
{
Runspace runspace = RunspaceFactory.CreateRunspace();
RunspaceConfiguration runConfig = RunspaceConfiguration.Create();

PSSnapInException psEx = null;
runConfig.AddPSSnapIn("OSAPS", out psEx);
runspace = RunspaceFactory.CreateRunspace(runConfig);

runspace.Open();

Pipeline pipeline = runspace.CreatePipeline();
pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(script);
pipeline.Commands.Add("Out-String");

Expand All @@ -50,12 +67,23 @@ private void RunScript(string script)

logging.AddToLog("Script return: " + stringBuilder.ToString(), false);

runspace.Close();
}
catch (Exception ex)
{
logging.AddToLog("An error occured while trying to run the script, details: \r\n" + ex.Message, true);
}
finally
{
if (pipeline != null)
{
pipeline.Dispose();
}
if (runspace != null)
{
runspace.Close();
runspace.Dispose();
}
}
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Plugins/OSAE.PowerShellProcessor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("OSAE.PowerShellProcessor")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("Script Processor for Open Source Automation")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Open Source Automation")]
[assembly: AssemblyProduct("OSAE.PowerShellProcessor")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[assembly: AssemblyTrademark("")]
Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("0.0.0.1")]
[assembly: AssemblyFileVersion("0.0.0.1")]

0 comments on commit 65c8c34

Please sign in to comment.