Hello Ben,
Here's how I would do it (I tested this approach and it works just fine)
* First of all (prerequisites):
- You *of course* need to have Powershell installed on your box
- You also need to have the Powershell SDK installed on your box (as far as I know the SDK is no longer available as a separate download, so you'll need to install the "Windows SDK for Windows Server 2008 and .NET Framework 3.5" (don't worry you won't need all of it - installing 'Developer tools - Windows Development Tools - .NET Development Tools' should do the trick).
- And ... if you want to use any of the VI Toolkit cmdlets (the VmWare stuff) you need to have the VI Toolkit installed (make sure you add the Snapin in the beginning of your Powershell script (add-pssnapin VMWare.VimAutomation.Core).
* Now once all this stuff is taken care of go to your Workflow Project
In your project tab under the tab "Libraries" add the following dll:
C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll
Now go to your model and add a Code (Script) Component and set the following properties for this component:
1. Input parameters:
Name: PSInput (or whatever variable containing the contents of your Powershell script)
Type: Text
2. Result Variable:
Result Variable Name: PSOutput (make sure this one exists)
Result Variable Type: Text
3. Source Code:
Language: C Sharp
Using namespaces (one per line (you might want to reconsider this ...)): System.Collections.ObjectModel
System.Management.Automation
System.Management.Automation.Runspaces
Source Code:
// Source:
http://www.codeproject.com/KB/cs/HowToRunPowerShell.aspx
// create Powershell runspace
Runspace runspace = RunspaceFactory.CreateRunspace();
// open it
runspace.Open();
// create a pipeline and feed it the script text
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(PSInput);
// add an extra command to transform the script
// output objects into nicely formatted strings
// remove this line to get the actual objects
// that the script returns. For example, the script
// "Get-Process" returns a collection
// of System.Diagnostics.Process instances.
pipeline.Commands.Add("Out-String");
// execute the script
Collection<psobject /> results = pipeline.Invoke();
// close the runspace
runspace.Close();
// convert the script result into a single string
StringBuilder stringBuilder = new StringBuilder();
foreach (PSObject obj in results)
{
stringBuilder.AppendLine(obj.ToString());
}
return stringBuilder.ToString();
* Now Connect this component to whatever other components you are using in this model
* Make sure you feed this component your powershell script
* The variable psoutput will contain whatever output your script generated (in your case the $AvailableSpace variable).
I hope this helps (if not, send me a message).
Best regards,
John