Suppress console outputs

I have a script reading some informations with Util.Cmd() from multiple remote servers...
Util.Cmd($"wmic /node:\"{srv.server}\" OS get LastBootUpTime");
At the end I will display the results in a table.
All works fine, but I'm wondering if it's possible to suppress the console outputs of the Util.Cmd() on the result screen.

At the moment I have to clean up the output bevore I put my table on the result screen.

Thanks in advance
Ifrit

Comments

  • edited May 14
    Util.Cmd has a quiet overload:
    Util.Cmd($"wmic /node:\"{srv.server}\" OS get LastBootUpTime", true);
  • Thank you very much for the quick response.
    I should have thought of that myself :#
  • edited May 14
    No problem. Instead of spawning a command line application (and having to parse the text based output), you could also take a look at the built in C# WMI classes to fetch system data.

    Example from https://social.msdn.microsoft.com/Forums/vstudio/en-US/85271fd8-3cc2-4011-92a7-294d0d008945/i-need-to-list-system-boot-time-for-a-remote-server?forum=netfxbcl
    using System.Management;
    
    var searcher =
      new ManagementObjectSearcher(
        [email protected]"\\{srv.server}\root\CIMV2",
        "SELECT * FROM Win32_OperatingSystem");
    
    foreach (var queryObj in searcher.Get())
    {
      Console.WriteLine("-----------------------------------");
      Console.WriteLine("Win32_OperatingSystem instance");
      Console.WriteLine("-----------------------------------");
      Console.WriteLine($"LastBootUpTime: {ManagementDateTimeConverter.ToDateTime(queryObj["LastBootUpTime"].ToString())}");
    }
    
  • This was a greate help!
    Thank you very much.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!