2016-03-30 14:20:52 -07:00
|
|
|
/********************************************************************++
|
|
|
|
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
--********************************************************************/
|
|
|
|
|
|
|
|
|
|
using System.Management.Automation;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerShell.Commands
|
|
|
|
|
{
|
|
|
|
|
#region WriteOutputCommand
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This class implements Write-output command
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2016-08-23 21:21:31 -04:00
|
|
|
[Cmdlet("Write", "Output", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113427", RemotingCapability = RemotingCapability.None)]
|
2016-03-30 14:20:52 -07:00
|
|
|
public sealed class WriteOutputCommand : PSCmdlet
|
|
|
|
|
{
|
2016-07-29 13:02:49 -07:00
|
|
|
private PSObject[] _inputObjects = null;
|
2016-03-30 14:20:52 -07:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Holds the list of objects to be Written
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true, ValueFromRemainingArguments = true)]
|
|
|
|
|
[AllowNull]
|
|
|
|
|
[AllowEmptyCollection]
|
|
|
|
|
public PSObject[] InputObject
|
|
|
|
|
{
|
2016-07-29 13:02:49 -07:00
|
|
|
get { return _inputObjects; }
|
|
|
|
|
set { _inputObjects = value; }
|
2016-03-30 14:20:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Prevents Write-Output from unravelling collections passed to the InputObject
|
|
|
|
|
/// parameter.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Parameter()]
|
|
|
|
|
public SwitchParameter NoEnumerate
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// This method implements the ProcessRecord method for Write-output command
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void ProcessRecord()
|
|
|
|
|
{
|
2016-07-29 13:02:49 -07:00
|
|
|
if (null == _inputObjects)
|
2016-03-30 14:20:52 -07:00
|
|
|
{
|
2016-07-29 13:02:49 -07:00
|
|
|
WriteObject(_inputObjects);
|
2016-03-30 14:20:52 -07:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool enumerate = true;
|
|
|
|
|
if (NoEnumerate.IsPresent)
|
|
|
|
|
{
|
|
|
|
|
enumerate = false;
|
|
|
|
|
}
|
2016-07-29 13:02:49 -07:00
|
|
|
foreach (PSObject inputObject in _inputObjects) // compensate for ValueFromRemainingArguments
|
2016-03-30 14:20:52 -07:00
|
|
|
{
|
|
|
|
|
WriteObject(inputObject, enumerate);
|
|
|
|
|
}
|
|
|
|
|
}//processrecord
|
|
|
|
|
}//WriteOutputCommand
|
|
|
|
|
#endregion
|
|
|
|
|
}
|