<< Back to Script Library

Add Computer to ControlUp

Adds the chosen computer, which already has the ControlUp agent installed and running, to the chosen ControlUp folder.

Must be run on a machine running the ControlUp Monitor Service (this is not the ControlUp Agent Service)
Version: 1.1.10
Created: 2020-05-11
Modified: 2020-06-03
Creator: Guy Leech
Downloads: 79
Tags: agent controlup
The Script Copy Script Copied to clipboard
<#
    Add specified machines to CU monitoring - must be run on machine running CU Monitor.

    @guyrleech 11/05/20
#>

[CmdletBinding()]

Param
(
    [Parameter(Mandatory,HelpMessage='Computer to add to CU')]
    [string]$computerName ,
    [Parameter(HelpMessage='ControlUp Folder to put computer in')]
    [string]$folderName
)

$ErrorActionPreference = 'Stop'
$VerbosePreference = 'SilentlyContinue'
$DebugPreference = 'SilentlyContinue'

if( ! ( $cuMonitorService = Get-CimInstance -ClassName win32_service -Filter "Name = 'cuMonitor'" ) )
{
    Throw "Unable to find the ControlUp Monitor service which is required for this script to run"
}

[string]$cudll = Join-Path -Path (Split-Path -Path ($cuMonitorService.PathName -replace '"') -Parent) -ChildPath 'ControlUp.PowerShell.User.dll'

if( ! (Test-Path -Path $cudll -PathType Leaf -ErrorAction SilentlyContinue ) )
{
    Throw "Unable to find `"$cudll`" which should be in the same folder as `"$cuMonitorService`""
}

if( ! ( $imported = Import-Module -Name $cudll -PassThru ) )
{
    Throw "Failed to import the PowerShell module in `"$cudll`""
}

Add-CUComputer -ADComputerName $computerName -DomainName $env:USERDNSDOMAIN -FolderPath $folderName

if( ! $? )
{
    Throw "Problem adding $computername.$domainname to folder `"$folderName`""
}