public void execute_ps_script()
{
PowerShell ps = PowerShell.Create();
ps.AddScript(" Invoke-RestMethod -Uri https://blogs.msdn.microsoft.com/powershell/feed/ | Format-Table -Property Title, pubDate");
{
Collection<PSObject> results = ps.Invoke();
foreach (var result in results)
{
Console.WriteLine(result);
}
}
}
If I run the above code with breakpoint at console.WriteLine()
:
Variable | Value |
---|---|
result | {Microsoft.PowerShell.Commands.Internal.Format.FormatStartData} |
results | Count = 14 |
14 values in results
are:
{Microsoft.PowerShell.Commands.Internal.Format.FormatStartData}
The output for Invoke-RestMethod -Uri https://blogs.msdn.microsoft.com/powershell/feed/ | Format-Table -Property Title, pubDate
in PowerShell is:
title pubDate
----- -------
Preview updating PowerShell 7.2 with Microsoft Update Wed, 16 Jun 2021 16:29:05 +0000
PowerShell for Visual Studio Code May 2021 Update Wed, 02 Jun 2021 23:18:17 +0000
SecretManagement Module v1.1.0 preview update Tue, 25 May 2021 18:30:36 +0000
Announcing PlatyPS 2.0.0-Preview1 Thu, 20 May 2021 19:08:32 +0000
Announcing PSDesiredStateConfiguration on PowerShell Gallery Fri, 14 May 2021 17:46:23 +0000
Announcing PowerShell Crescendo Preview.2 Thu, 06 May 2021 15:24:25 +0000
Optimizing your $Profile Tue, 06 Apr 2021 18:55:09 +0000
Announcing the preview of PSArm Wed, 31 Mar 2021 17:02:54 +0000
SecretManagement and SecretStore are Generally Available Thu, 25 Mar 2021 18:22:07 +0000
SecretStore Release Candidate 3 Mon, 15 Mar 2021 22:12:04 +0000
How do I get the same output in Visual Studio when running PowerShell command using C#?