Example #1
0
 public pshell()
 {
     try
     {
         pspath = poshsecframework.Properties.Settings.Default["ScriptPath"].ToString();
         ps = new pscript();
         ps.ScriptCompleted += new EventHandler<pseventargs>(ScriptCompleted);
         if (ps.LoadErrors != "")
         {
             loaderrors = ps.LoadErrors;
         }
     }
     catch (Exception e)
     {
         //Base Exception Handler
         MessageBox.Show(StringValue.UnhandledException + Environment.NewLine + e.Message + Environment.NewLine + "Stack Trace:" + Environment.NewLine + e.StackTrace);
     }
 }
Example #2
0
 public void Close()
 {
     ps.Close();
     ps = null;
     GC.Collect();
 }
Example #3
0
 public void Open()
 {
     ps = new pscript(frm);
     ps.ScriptCompleted += new EventHandler<pseventargs>(ScriptCompleted);
 }
Example #4
0
 public void Close()
 {
     ps.Close();
     ps = null;
     GC.Collect();
 }
Example #5
0
 public void Open()
 {
     ps = new pscript(frm);
     ps.ScriptCompleted += new EventHandler <pseventargs>(ScriptCompleted);
 }
Example #6
0
 private void GetCommand()
 {
     try
     {
         PShell.pscript ps = new PShell.pscript();
         ps.ParentForm = this;
         Collection<PSObject> rslt = ps.GetCommand();
         ps = null;
         if (rslt != null)
         {
             List<String> accmds = new List<String>();
             lvwCommands.Items.Clear();
             lvwCommands.BeginUpdate();
             foreach (PSObject po in rslt)
             {
                 ListViewItem lvw = null;
                 switch (po.BaseObject.GetType().Name)
                 {
                     case "AliasInfo":
                         AliasInfo ai = (AliasInfo)po.BaseObject;
                         if (btnShowAliases.Checked)
                         {
                             lvw = new ListViewItem();
                             lvw.Text = ai.Name;
                             lvw.ToolTipText = ai.Name;
                             lvw.SubItems.Add(ai.ModuleName);
                             lvw.ImageIndex = (int)LibraryImages.Alias;
                             accmds.Add(ai.Name);
                         }
                         break;
                     case "FunctionInfo":
                         FunctionInfo fi = (FunctionInfo)po.BaseObject;
                         if (btnShowFunctions.Checked)
                         {
                             lvw = new ListViewItem();
                             lvw.Text = fi.Name;
                             lvw.ToolTipText = fi.Name;
                             lvw.SubItems.Add(fi.ModuleName);
                             lvw.ImageIndex = (int)LibraryImages.Function;
                             accmds.Add(fi.Name);
                         }
                         break;
                     case "CmdletInfo":
                         CmdletInfo cmi = (CmdletInfo)po.BaseObject;
                         if (btnShowCmdlets.Checked)
                         {
                             lvw = new ListViewItem();
                             lvw.Text = cmi.Name;
                             lvw.ToolTipText = cmi.Name;
                             lvw.SubItems.Add(cmi.ModuleName);
                             lvw.ImageIndex = (int)LibraryImages.Cmdlet;
                             accmds.Add(cmi.Name);
                         }
                         break;
                     default:
                         Console.WriteLine(po.BaseObject.GetType().Name);
                         break;
                 }
                 if (lvw != null && (cmbLibraryTypes.Text == "All" || cmbLibraryTypes.Text.ToLower() == lvw.SubItems[1].Text.ToLower()))
                 {
                     lvwCommands.Items.Add(lvw);
                 }
                 else
                 {
                     lvw = null;
                 }
             }
             lvwCommands.EndUpdate();
             accmds.Sort();
             txtPShellOutput.AutoCompleteCommands = accmds;
         }
     }
     catch (Exception e)
     {
         DisplayError(e);
     }
 }
Example #7
0
        private void ScheduleScript()
        {
            try
            {
                List<PShell.psparameter> scriptparams;
                ListViewItem lvw = lvwScripts.SelectedItems[0];
                PShell.pscript psc = new PShell.pscript();
                psc.ParentForm = this;
                scriptparams = psc.CheckForParams(lvw.Tag.ToString());

                if (!psc.ParamSelectionCancelled)
                {
                    Utility.ScheduleItem sitm = new Utility.ScheduleItem();
                    sitm.ScriptName = lvw.Text;
                    sitm.ScriptPath = lvw.Tag.ToString();
                    sitm.RunAs = Enums.EnumValues.RunAs.CurrentUser;
                    if (scriptparams != null && scriptparams.Count > 0)
                    {
                        foreach (PShell.psparameter prm in scriptparams)
                        {
                            sitm.Parameters.Properties.Add(prm);
                        }
                    }
                    Interface.frmSchedule sched = new Interface.frmSchedule();
                    if (sched.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        sitm.ScheduledTime = sched.ScheduledTime;
                        sitm.Index = GetScheduleIndex();
                        schedule.ScheduleItems.Add(sitm);
                        if (schedule.Save())
                        {
                            LoadSchedule();
                        }
                        else
                        {
                            MessageBox.Show("Error saving schedule: " + schedule.LastException.Message);
                        }
                    }
                    sched = null;
                }
            }
            catch (Exception e)
            {
                DisplayError(e);
            }
        }