Beispiel #1
0
        private void RunScriptCode()
        {
            string powerShellScript    = GetStringProperty(Constants.SOProperties.SimplePowerShell.PowerShellScript, true);
            string serializedVariables = GetStringProperty(Constants.SOProperties.SimplePowerShell.Variables, false);

            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = ServiceBroker.ServicePackage.ResultTable;

            //deserialize variables
            List <PowerShellVariablesDC> variablesList = new List <PowerShellVariablesDC>();

            if (!String.IsNullOrEmpty(serializedVariables))
            {
                variablesList = PowerShellSerializationHelper.DeserializeArrayToList(serializedVariables);
            }

            //run script
            string scriptOutput = PowerShellHelper.RunScriptCode(powerShellScript, variablesList);

            DataRow dr = results.NewRow();

            dr[Constants.SOProperties.SimplePowerShell.ScriptOutput] = scriptOutput;
            if (variablesList.Count != 0)
            {
                dr[Constants.SOProperties.SimplePowerShell.Variables] = PowerShellSerializationHelper.SerializeList(variablesList);
            }
            else
            {
                dr[Constants.SOProperties.SimplePowerShell.Variables] = String.Empty;
            }

            results.Rows.Add(dr);
        }
        private void DeserializeArrayToList()
        {
            string serializedArray = GetStringProperty(Constants.SOProperties.PowershellVariables.SerializedArray, true);

            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = ServiceBroker.ServicePackage.ResultTable;

            List <PowerShellVariablesDC> powerShellVariablesList = PowerShellSerializationHelper.DeserializeArrayToList(serializedArray);

            foreach (PowerShellVariablesDC item in powerShellVariablesList)
            {
                DataRow dr = results.NewRow();
                dr[Constants.SOProperties.PowershellVariables.Name]  = item.Name;
                dr[Constants.SOProperties.PowershellVariables.Value] = item.Value;
                results.Rows.Add(dr);
            }
        }
        private void RunScript()
        {
            string serializedVariables = GetStringProperty(Constants.SOProperties.SimplePowerShell.Variables, false);

            ServiceObject serviceObject = ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = ServiceBroker.ServicePackage.ResultTable;

            //get script path
            string metaDataScriptPath = serviceObject.Methods[0].MetaData.GetServiceElement <string>(Constants.SOProperties.DynamicPowerShell.MetaDataScriptPath);

            //deserialize variables
            List <PowerShellVariablesDC> variablesList = new List <PowerShellVariablesDC>();

            if (!String.IsNullOrEmpty(serializedVariables))
            {
                variablesList = PowerShellSerializationHelper.DeserializeArrayToList(serializedVariables);
            }

            //run script from file
            string scriptOutput = PowerShellHelper.RunScriptFile(metaDataScriptPath, variablesList);

            DataRow dr = results.NewRow();

            dr[Constants.SOProperties.DynamicPowerShell.ScriptOutput] = scriptOutput;
            if (variablesList.Count != 0)
            {
                dr[Constants.SOProperties.DynamicPowerShell.Variables] = PowerShellSerializationHelper.SerializeList(variablesList);
            }
            else
            {
                dr[Constants.SOProperties.DynamicPowerShell.Variables] = String.Empty;
            }

            results.Rows.Add(dr);
        }