I trying to execute a simple powershell command in c# and output the result. Powershell v5.1 on Server 2016
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-DhcpServerInDC");
Collection<PSObject> results = ps.Invoke();
StringBuilder sb = new StringBuilder();
foreach (PSObject obj in results) {
sb.AppendLine(obj.ToString()); }
txt_adt_updateTextbox.Text = sb.ToString();
But instead of getting a list of DHCP servers and their IP addresses, I get the following.
DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC DhcpServerInDC