diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/write.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/write.cs
index 88cc499978..d311e571a7 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/write.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/write.cs
@@ -171,13 +171,13 @@ namespace Microsoft.PowerShell.Commands
/// This class implements Write-Information command
///
///
- [Cmdlet("Write", "Information", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=525909", RemotingCapability = RemotingCapability.None)]
+ [Cmdlet(VerbsCommunications.Write, "Information", HelpUri = "https://go.microsoft.com/fwlink/?LinkId=525909", RemotingCapability = RemotingCapability.None)]
public sealed class WriteInformationCommand : PSCmdlet
{
///
/// Object to be sent to the Information stream.
///
- [Parameter(Position = 0, Mandatory = true)]
+ [Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true)]
[Alias("Msg")]
public Object MessageData { get; set; }
@@ -206,10 +206,18 @@ namespace Microsoft.PowerShell.Commands
}
}
}
+ }
+ ///
+ /// This method implements the ProcessRecord method for Write-Information command
+ ///
+ protected override void ProcessRecord()
+ {
WriteInformation(MessageData, Tags);
}
+
}//WriteInformationCommand
+
#endregion WriteInformationCommand
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1
index 859fb2afc4..c6447e393a 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1
@@ -70,6 +70,19 @@ Describe "Stream writer tests" -Tags "CI" {
}
Context "Write-Information cmdlet" {
+ BeforeAll {
+ $ps = [powershell]::Create()
+ }
+
+ BeforeEach {
+ $ps.Commands.Clear()
+ $ps.Streams.ClearStreams()
+ }
+
+ AfterAll {
+ $ps.Dispose()
+ }
+
It "Write-Information outputs an information object" {
# redirect the streams is sufficient
$result = Write-Information "Test Message" *>&1
@@ -89,5 +102,13 @@ Describe "Stream writer tests" -Tags "CI" {
}
"$result" | Should be "Test Message"
}
+
+ It "Write-Information accept objects from pipe" {
+ $ps.AddScript("'teststring',12345 | Write-Information -InformationAction Continue").Invoke()
+ $result = $ps.Streams.Information
+ $result.Count | Should be 2
+ $result[0].MessageData | Should be "teststring"
+ $result[1].MessageData | Should be "12345"
+ }
}
}