Quantcast
Channel: foreach | Operating systems, scripting, PowerShell and security | jesusninoc.com
Viewing all articles
Browse latest Browse all 409

Ejecutar el cmdlet de PowerShell que recupera el contenido de la caché de cliente DNS desde C#

$
0
0

using System;
using System.Management.Automation;  // Windows PowerShell namespace.

namespace HostPS1
{
    class HostPS1
    {
        static void Main(string[] args)
        {

            // Call the PowerShell.Create() method to create an
            // empty pipeline.
            PowerShell ps = PowerShell.Create();

            // Call the PowerShell.AddCommand(string) method.
            ps.AddCommand("Get-DnsClientCache");

            Console.WriteLine("Entry                 Data");
            Console.WriteLine("----------------------------");


            // Call the PowerShell.Invoke() method to run the
            // commands of the pipeline in the default runspace.
            foreach (PSObject result in ps.Invoke())
            {
                Console.WriteLine("{0,-24}{1}",
                        result.Members["Entry"].Value,
                        result.Members["Data"].Value);
            } // End foreach.
        } // End Main.
    } // End HostPs1.
}

The post Ejecutar el cmdlet de PowerShell que recupera el contenido de la caché de cliente DNS desde C# appeared first on Scripting and security.


Viewing all articles
Browse latest Browse all 409

Trending Articles