// Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of System.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Depth.Expression != null)
            {
                targetCommand.AddParameter("Depth", Depth.Get(context));
            }

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (NoTypeInformation.Expression != null)
            {
                targetCommand.AddParameter("NoTypeInformation", NoTypeInformation.Get(context));
            }

            if (As.Expression != null)
            {
                targetCommand.AddParameter("As", As.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
Exemplo n.º 2
0
        protected override void ProcessRecord()
        {
            StringBuilder line = new StringBuilder();

            if ((!NoTypeInformation.ToBool()) && (!typeWritten))
            {
                file.WriteLine("#TYPE " + InputObject.GetType().ToString());
                typeWritten = true;
            }

            foreach (PSPropertyInfo _prop in InputObject.Properties)
            {
                line.Append(_prop.Value.ToString());
                line.Append(',');
            }

            // Remove the trailing comma
            line.Remove((line.Length - 1), 1);

            file.WriteLine(line.ToString());
        }