Exemplo n.º 1
0
        /// <summary>
        /// Add a command to construct a command pipeline.
        /// For example, to construct a command string "get-process | sort-object",
        ///     <code>
        ///         PSCommand command = new PSCommand("get-process").AddCommand("sort-object");
        ///     </code>
        /// </summary>
        /// <param name="command">
        /// A string representing the command.
        /// </param>
        /// <exception cref="InvalidPowerShellStateException">
        /// Powershell instance cannot be changed in its
        /// current state.
        /// </exception>
        /// <returns>
        /// A PSCommand instance with <paramref name="cmdlet"/> added.
        /// </returns>
        /// <remarks>
        /// This method is not thread safe.
        /// </remarks>
        /// <exception cref="ArgumentNullException">
        /// cmdlet is null.
        /// </exception>
        public PSCommand AddCommand(string command)
        {
            if (command == null)
            {
                throw PSTraceSource.NewArgumentNullException("cmdlet");
            }

            if (_owner != null)
            {
                _owner.AssertChangesAreAccepted();
            }

            _currentCommand = new Command(command, false);
            _commands.Add(_currentCommand);

            return(this);
        }