Public/Get-SwEngine.ps1

Function Get-SwEngine {
    <#
        .SYNOPSIS
        Return Polling Engines from solarwinds database
 
        .DESCRIPTION
        This function gets an InfoServiceProxy and a name or ID related to a Polling Engines. after that can retrive usefull information in object format.
        Note: Name and Id could not be used at the same time.
        If you use name, function will find all Polling Engines which can match this name partially.
        If you do not define name or Id, Function will return all Polling Engines in database
 
        .EXAMPLE
        PS> Get-SwEngine -InfoServiceProxy $swsi -Name "MainPoller-01"
 
        Id : 1
        Name : MainPoller-01
        IP : 192.168.10.11
        ServerType : Primary
        Elements : 6524
        Nodes : 269
        Interfaces : 5749
        Volumes : 506
 
        .EXAMPLE
        PS> Get-SwEngine -InfoServiceProxy $swsi -Id 1
 
        Id : 1
        Name : MainPoller-01
        IP : 192.168.10.11
        ServerType : Primary
        Elements : 6524
        Nodes : 269
        Interfaces : 5749
        Volumes : 506
    #>

    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [SolarWinds.InformationService.Contract2.InfoServiceProxy]$InfoServiceProxy,

        [string]$Name,

        [int]$Id
    )

    Begin{
        if ($PSBoundParameters.ContainsKey('Name') -and $PSBoundParameters.ContainsKey('Id') ){
            Write-Error("Both Name and Id can not be used at the same time")
            return
        }

        $query = "SELECT Engineid,ServerName,IP,ServerType,Elements, `
                    Nodes,Interfaces,Volumes FROM Orion.engines"


        if ($PSBoundParameters.ContainsKey('Name')){
            $query += " WHERE ServerName Like '$Name%'"
        }
        elseif ($PSBoundParameters.ContainsKey('Id')) {
            $stringId = $Id.ToString()
            $query += " WHERE EngineID = '$stringId'"
        }
    }
    Process{
        Write-Verbose -Message "Fetching query from server ..."
        $result = Get-SwisData -SwisConnection $InfoServiceProxy -Query $query
        if($null -eq $result){
            return $null
        }
        elseif ($result.length -eq 1) {
            return ConvertTo-SwEngine -Object $result
        }
        else{
            [Parmis.SolarWinds.Engine[]]$output = @()
            foreach ($item in $result ){
                $output += ConvertTo-SwEngine -Object $item
            }
            return($output)
        }
    }

    End{
    }
}