Webroot scan an Endpoint

Shows how to scan an Endpoint with the specified HostName.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.ServiceModel;

namespace DemoWebRootSiteCommandsPost
{
    class Program
    {
        /*
         * Instructions
         * 
         * 1. Disable Authentication and SSL.
         * 2. Add a Service Reference to the WebRoot Service, name the reference WebRootService.
         *    The uri will generally be http://localhost:11111/WebRoot.
         * 3. With new release you may have to update the Service Reference.
         * 4. You will need to replace the strings: console, siteName and hostName with the correct values.
         */
        static void Main(string[] args)
        {
            string console = "Default";
            string siteName = "Cats and Dogs";
            string hostName = "Fred";

            WebRootService.ConsoleGSMClient consoleGSMClient = new WebRootService.ConsoleGSMClient();
            (consoleGSMClient.ChannelFactory.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
            (consoleGSMClient.ChannelFactory.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
            (consoleGSMClient.ChannelFactory.Endpoint.Binding as BasicHttpBinding).ReceiveTimeout = new TimeSpan(0, 10, 0);

            WebRootService.GetGSMSitesResponseModel sites = consoleGSMClient.SitesGet(console);
            string siteId = null;
            for (int i = 0; i < sites.Sites.Length; i++)
            {
                if (sites.Sites[i].SiteName == siteName)
                {
                    siteId = sites.Sites[i].SiteId;
                    break;
                }
            }

            WebRootService.GetEndpointsResponseModel endpoints = consoleGSMClient.SiteEndpointsGet(console, siteId,
                null, null, null, null, null, null, null);

            string endpointId = null;
            for (int i = 0; i < endpoints.Endpoints.Length; i++)
            {
                if (endpoints.Endpoints[i].HostName == hostName)
                {
                    endpointId = endpoints.Endpoints[i].EndpointId;
                    break;
                }
            }


            bool siteCommandsPost = consoleGSMClient.SiteCommandsPost(console, siteId,
                new WebRootService.SetCommandRequestModel { EndpointsList = endpointId, Command = "scan" });
            Console.WriteLine($"siteCommandsPost: {siteCommandsPost}");

            Console.WriteLine("Press enter to continue.");
            Console.ReadLine();
        }
    }
}
PowerShell
# Instructions
#
# 1. Disable Authentication and SSL
# 2. You will need to replace the strings: console, siteName and hostName with the correct values.

$console = "Default"
$siteName = "Cats and Dogs"
$hostName = "Fred"

$Uri = 'http://127.0.0.1:11111/WebRoot'
$Xml = @'
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
    soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soap:Body>
    {0}
  </soap:Body>
</soap:Envelope>
'@

# Get the siteId
$Body = @'
<SitesGet>
    <Console>{0}</Console>
</SitesGet>
'@ -f $console 
$result = (Invoke-WebRequest -UseBasicParsing -Body ($Xml -f $Body) `
    -method POST –contentType "text/xml" -Uri $Uri -Headers @{"SOAPAction"="urn:IConsoleGSM/SitesGet"})
$sites = ([xml]$result.content).Envelope.Body.SitesGetResponse.SitesGetResult.Sites
$siteId = $null
foreach ($site in $sites.SelectNodes("GetGSMSitesResponseModel_Site"))
{
    if ($site.SiteName -eq $siteName)
    {
        $siteId = $site.SiteId
        break
    }
}

# Get the endpointId
$Body = @'
    <SiteEndpointsGet>
      <Console>{0}</Console>
      <SiteId>{1}</SiteId>
      <Type />
      <HostName />
      <MachineId />
      <Order />
      <OrderDirection />
      <PageSize />
      <PageNr />
    </SiteEndpointsGet>
'@ -f $console, $siteId
$result = (Invoke-WebRequest -UseBasicParsing -Body ($Xml -f $Body) `
    -method POST –contentType "text/xml" -Uri $Uri -Headers @{"SOAPAction"="urn:IConsoleGSM/SiteEndpointsGet"})
$endpoints = ([xml]$result.content).Envelope.Body.SiteEndpointsGetResponse.SiteEndpointsGetResult.Endpoints
$endpointId = $null
foreach ($endpoint in $endpoints.SelectNodes("GetEndpointsResponseModel_Endpoint"))
{
    if ($endpoint.HostName -eq $hostName)
    {
        $endpointId = $endpoint.EndpointId
        break
    }
}

# Scan the endpoint
$Body = @'
<SiteCommandsPost>
    <Console>{0}</Console>
    <SiteId>{1}</SiteId>
    <Commands>
        <EndpointsList>{2}</EndpointsList>
        <Command>scan</Command>
    </Commands>
</SiteCommandsPost>
'@ -f $console, $siteId, $endpointId
$result = (Invoke-WebRequest -UseBasicParsing -Body ($Xml -f $Body) `
    -method POST –contentType "text/xml" -Uri $Uri -Headers @{"SOAPAction"="urn:IConsoleGSM/SiteCommandsPost"})
$siteCommandsPost = ([xml]$result.content).Envelope.Body.SiteCommandsPostResponse.SiteCommandsPostResult
Write-Output "siteCommandsPost: $siteCommandsPost"