Skip to content

Instantly share code, notes, and snippets.

@rwilkes
Forked from jamessantiago/PowershellModule.csx
Last active March 22, 2017 06:02
Show Gist options
  • Save rwilkes/b14172e64293880e61f1 to your computer and use it in GitHub Desktop.
Save rwilkes/b14172e64293880e61f1 to your computer and use it in GitHub Desktop.
MMBot script for use with the MMBot.Powershell package
//Notes:
//Requires the MMBot.Powershell nuget package
//Specify the powershell scripts folder using the MMBOT_POWERSHELL_SCRIPTSPATH key in the ini file
//Powershell scripts must be .psm1 (modules) to be executed
//Only scripts inside the scripts folder may be executed using this script
//Output objects must either support a ToString method or be a string to display properly
using MMBot.Powershell;
var robot = Require<Robot>();
robot.Respond(@"(psm|powershell module) (.*)", msg =>
{
var command = msg.Match[2];
try
{
foreach (string result in robot.ExecutePowershellModule(command))
{
msg.Send(result);
}
}
catch (Exception)
{
msg.Send("erm....issues, move along");
}
});
robot.AddHelp("mmbot powershell module <module> <parameters> - Executes a powershell module from the [MMBOT_POWERSHELL_SCRIPTSPATH] path.");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment