Webroot Create Site

Shows how to add a Site to a Console.

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

using System.ServiceModel;

namespace DemoWebRootSitePost
{
    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 variables: console, siteName, seats, comments and emails with the correct values.
         */
        static void Main(string[] args)
        {
            string console = "Default";
            string siteName = "Cats and Dogs";
            int seats = 10;
            string comments = "Cats and Dogs";
            string emails = "catsanddogs@example.com";

            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.CreateGSMSiteResponseModel createGSMSite = consoleGSMClient.SitePost(console, new WebRootService.CreateGSMSiteRequestModel
            {
                SiteName = siteName,
                Seats = seats,
                Comments = comments,
                BillingCycle = null,
                BillingDate = null,
                GlobalPolicies = false,
                GlobalOverrides = false,
                PolicyId = null,
                Emails = emails,
                Trial = false,
                Modules = new WebRootService.CreateGSMSiteRequestModel_Module[0]
            });
            Console.WriteLine($"KeyCode: {createGSMSite.KeyCode}");
            Console.WriteLine($"SiteId: {createGSMSite.SiteId}");
            Console.WriteLine($"PCAccess: {createGSMSite.PCAccess}");
            Console.WriteLine($"MSAccess: {createGSMSite.MSAccess}");

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

$console = "Default"
$siteName = "Cats and Dogs"
$seats = "10"
$comments = "Cats and Dogs"
$emails = "catsanddogs@example.com"

$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>
'@

# Create a new site
$Body = @'
<SitePost>
  <Console>{0}</Console>
  <Site>
	<SiteName>{1}</SiteName>
	<Seats>{2}</Seats>
	<Comments>{3}</Comments>
	<GlobalPolicies>false</GlobalPolicies>
	<GlobalOverrides>false</GlobalOverrides>
	<Emails>{4}</Emails>
	<Trial>false</Trial>
	<Modules />
  </Site>
</SitePost>
'@ -f $console, $siteName, $seats, $comments, $emails
$result = (Invoke-WebRequest -UseBasicParsing -Body ($Xml -f $Body) `
    -method POST –contentType "text/xml" -Uri $Uri -Headers @{"SOAPAction"="urn:IConsoleGSM/SitePost"})
$sitePostResult = ([xml]$result.content).Envelope.Body.SitePostResponse.SitePostResult
Write-Output "KeyCode: $($sitePostResult.KeyCode)"
Write-Output "SiteId: $($sitePostResult.SiteId)"
Write-Output "PCAccess: $($sitePostResult.PCAccess)"
Write-Output "MSAccess: $($sitePostResult.MSAccess)"