Public/Install-SwAgent.ps1

Function Install-SwAgent {
    <#
        .SYNOPSIS
        Request install agent for a new node
 
        .DESCRIPTION
        by using this function you can install solarwinds agent on new node on your environment.
        at least 3 parameters is mandatory.
            1- Info Service Proxy (you can use Connect-SwInfoServiceProxy to create one)
            2- Computer name of tager machine
            3- Engine Id of your target polling engine
    #>

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

        [Parameter(Mandatory = $true)]
        [string]$ComputerName,

        [Parameter(Mandatory = $true)]
        [int]$EngineId
    )

    Begin{

    }
    Process{
        Write-Verbose -Message "Start to processing '$ComputerName' ..."
        $result = $null
        $result = Resolve-DnsName -Name $ComputerName -ErrorAction SilentlyContinue -Verbose:$false
        if($null -eq $result){
            Write-Verbose -Message "DNS Resolve for agent is failed. This agent is skiped."
            continue
        }
        $ip = ($result | Where-Object -Property Type -eq A).IPAddress
        Write-Verbose -Message "Execute installation command for $ComputerName"
        Invoke-SwisVerb -SwisConnection $InfoServiceProxy -EntityName "Orion.AgentManagement.Agent" -Verb "Deploy" -Arguments @(
            $EngineID,                                                         # ID of polling engine to which the Agent should be connected after deployment
            $ComputerName,                                                     # Name of the agent to show in UI
            $ComputerName,                                                     # Hostname to which agent should be deployed.
            $ip,                                                             # IP Address to which agent should be deployed.
            $InfoServiceProxy.ChannelFactory.Credentials.UserName.UserName,    # Username for deployment. This user is used to remotelly connect to target machine.
            $InfoServiceProxy.ChannelFactory.Credentials.UserName.Password,    # Password to connect to target machine or a private key in PEM format
            $null,                                                             # SUDO username. Can be empty or $null if running SUDO using $machineUsername.
            $null,                                                             # SUDO password.
            $false,                                                         # Should be $true if $machinePassword is not a password but an SSH private key.
            $null,                                                            # If $machinePassword contains SSH private key protected by a password the password goes here.
            1,                                                                # Agent Mode: 0 - automatic detection, 1 - force active agent, 2 - force passive agent
            $null                                                            # If deploying to unsupported Linux distribution
            ) | Out-Null
            Write-Verbose -Message "$ComputerName -> Installation command is successfully sent ..."
    }
    End{
        Write-Verbose -Message "Command is executed for all machines."
    }
}