コード例 #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);
        }
コード例 #2
0
        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);
        }