The .NET code to host and use the PowerShell engine is very simple:
private void ExecutePowerShellCommand(string command)
{
using (var invoker = new RunspaceInvoke())
{
Collection<PSObject> results = invoker.Invoke(command);
foreach (var result in results)
{
_listBox.Items.Add(result);
}
}
}
The trick is in configuring the PowerShell runspace to limit the available commands. You probably don't want to allow someone to delete files from any old directory, shutdown the computer or format a drive (they would have access to EXEs in the path). Look into Constrained Runspaces to limit what can be executed via this mechanism. You can also limit which language features are available.