en-US/about_PSSophos.help.txt

TOPIC
    about_pssophos
 
    This PowerShell module streamlines the administration of Sophos, enabling
    automated configuration for efficient setup. Ideal for release pipelines, it
    simplifies device management and ensures consistent deployment.
 
SHORT DESCRIPTION
    Powershell Wrapper for the Sophos APIs.
 
EXAMPLES
    The example below shows how the module can be used to add a local website to
    a tenant.
    !!! Example === "Script"
 
    title="Add-SophosLocalWebsite.ps1"
            [cmdletbinding(SupportsShouldProcess=$true, ConfirmImpact='High')]
            param(
                [Parameter(Mandatory=$true)]
                [string]$TenantName,
                [Parameter(Mandatory=$true)]
                [string]$Url,
                [Parameter(Mandatory=$true)]
                [string[]]$Tag,
                [Parameter(Mandatory=$true)]
                [string]$Comment,
                [Parameter(Mandatory=$true)]
                [pscredential]$Credential
            )
            Begin {
                try {
                    $AccessToken = Get-SophosAccessToken -Credential $Credential -ErrorAction Stop
                }
                catch {
                    throw $_.Exception.Message
                }
                if(-not ($AccessToken.Success))
                {
                    throw $AccessToken
                }
                $PartnerId = Get-SophosPartnerId -Token $AccessToken.Token
                if(-not ($PartnerId.Success))
                {
                    throw $PartnerId
                }
                $Output = $null
                 
            }
            Process {
                if($PSCmdlet.ShouldProcess($TenantName,'Add local website'))
                {
                    try {
                        $Results = Get-SophosPartnerTenant -Token $AccessToken.Token -PartnerId $PartnerId.PartnerId -ErrorAction Stop
                    }
                    catch{
                        throw $_.Exception.Message
                    }
                     
                    $Tenant = $Results.Result | Where-Object {$_.showAs -ieq "$TenantName"}
                    $web = New-SophosEndpointWebControlLocalSite -Token $AccessToken.Token -TenantId $Tenant.id -ApiHost $Tenant.apiHost -Url "$Url" -Tags $Tag -Comment "$Comment" -Confirm:$false
                    if(-not $($web.Success -ieq "True"))
                    {
                        throw $web
                    }
                    $Output = $web.Result
                }
            }
            End {
                return $Output
            }
 
    === "Function"
 
    title="Add-SophosLocalWebsite"
            function Add-SophosLocalWebsite {
                <#
                .SYNOPSIS
                Add local website to a tenant
                 
                .DESCRIPTION
                Add local website to a tenant
                 
                .PARAMETER TenantName
                Target tenant name
                 
                .PARAMETER Url
                URL to be added
                 
                .PARAMETER Tags
                Tags for the URL. Single or array of tags
                 
                .PARAMETER Comment
                Reason for adding the URL
                 
                .PARAMETER Credential
                PSCredential for the sophos API
                 
                .EXAMPLE
                PS>.\Add-SophosLocalWebsite.ps1 -TenantName "MyTenant" -Url "https://example.com" -Tags "example" -Comment "just testing" -Credential $Credential
                #>
                 
                [cmdletbinding(SupportsShouldProcess=$true, ConfirmImpact='High')]
                param(
                    [Parameter(Mandatory=$true)]
                    [string]$TenantName,
                    [Parameter(Mandatory=$true)]
                    [string]$Url,
                    [Parameter(Mandatory=$true)]
                    [string[]]$Tag,
                    [Parameter(Mandatory=$true)]
                    [string]$Comment,
                    [Parameter(Mandatory=$true)]
                    [pscredential]$Credential
                )
                Begin {
                    try {
                        $AccessToken = Get-SophosAccessToken -Credential $Credential -ErrorAction Stop
                    }
                    catch {
                        throw $_.Exception.Message
                    }
                    if(-not ($AccessToken.Success))
                    {
                        throw $AccessToken
                    }
                    $PartnerId = Get-SophosPartnerId -Token $AccessToken.Token
                    if(-not ($PartnerId.Success))
                    {
                        throw $PartnerId
                    }
                    $Output = $null
                     
                }
                Process {
                    if($PSCmdlet.ShouldProcess($TenantName,'Add local website'))
                    {
                        try {
                            $Results = Get-SophosPartnerTenant -Token $AccessToken.Token -PartnerId $PartnerId.PartnerId -ErrorAction Stop
                        }
                        catch{
                            throw $_.Exception.Message
                        }
                         
                        $Tenant = $Results.Result | Where-Object {$_.showAs -ieq "$TenantName"}
                        $web = New-SophosEndpointWebControlLocalSite -Token $AccessToken.Token -TenantId $Tenant.id -ApiHost $Tenant.apiHost -Url "$Url" -Tags $Tag -Comment "$Comment" -Confirm:$false
                        if(-not $($web.Success -ieq "True"))
                        {
                            throw $web
                        }
                        $Output = $web.Result
                    }
                }
                End {
                    return $Output
                }
            }
 
    !!! Execution
 
    === "Script"
 
    .\Add-SophosLocalWebsite.ps1 -TenantName "MyTenant" -Url "https://example.com" -Tags "example.com" -Comment "just testing" -Credential $Credential
 
    === "Function"
 
    Add-SophosLocalWebsite -TenantName "MyTenant" -Url "https://example.com" -Tags "example.com" -Comment "just testing" -Credential $Credential
 
NOTE
    This PowerShell module is provided "as-is" without any guarantees or
    warranty. Use it at your own risk. The authors and contributors are not
    responsible for any damage or issues that may arise from using this module.
 
LICENSE
    This project is under the
    MIT
    license.
 
KEYWORDS
    - Sophos
- Sophos API