Script Examples - Windows

The following examples show how to create an Agent object (HOST), download and extract an agent and /or TLS Gateway pack, and optionally install and start the ServiceManager for SQL, REST, and Windows Agents, as well as for the TLS Gateway.

Important! If you want to install and start the ServiceManager you must use RunAsAdministrator. Also, the ServiceManager installation is not secured. For more information, see CAPKI - Securing the ServiceManager.

This page includes the following:

REST Agent

The following parameters are used for the REST examples:

$AgentName = "REST13"
$SmgrPort = 8873
$SmgrName = "Automic"
$InstallFolder = "C:\temp\testrest"
$RestEndpoint = "https://hostname:8088"
$Client = 100
$Cred = Get-Credential

With ServiceManager

# Create HOST object
Write-Host "Create Agent $($AgentName)"
$ProgressPreference = "SilentlyContinue";
$AgentsUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agents"
$Body = @{
   "name" = $AgentName
   "template" = "AGENT.WEBSERVICEREST"
}
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentsUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 200) {
    throw "Failed to create agent object, status code was " + $result.StatusCode
}

# Download and extract agent package
Write-Host "Create Agent package"
$Body = @{
    "platform" = "RA"
    "name" = $AgentName
    "config_update" = "[GLOBAL]`nname=" + $AgentName
    "service_manager" = @{
        "operating_system" = "Windows"
        "operating_system_architecture" = "x64"
        "config_update" = "[GLOBAL]`nport=" + $SmgrPort + "`n[Destination " + $SmgrName + "]`ncmdfile=*OWN\uc4.smc`ndeffile=*OWN\uc4.smd"
    }
}
$AgentPackUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agentpacks/"
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentPackUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 201) {
    throw "Agent package has not been created, status code was " + $result.StatusCode
}
$AgentZip = $result.Headers['Location']
Write-Host "Download $($AgentZip)"
Invoke-WebRequest -Uri $AgentZip -Credential $Cred -OutFile "tmp.zip"
Expand-Archive -Path "tmp.zip" -DestinationPath $InstallFolder
Remove-Item -Path "tmp.zip"

#Install and start service manager
Write-Host "Install Service Manager"
$smgrExe = Join-Path -Path $InstallFolder -ChildPath "smgr\bin\ucybsmgr.exe" -Resolve
$SmgrWorkdir = Join-Path -Path $InstallFolder -ChildPath "smgr\bin" -Resolve
$SmgrArguments = "-install " + $SmgrName
Start-Process -FilePath $smgrExe -ArgumentList $SmgrArguments -WorkingDirectory $SmgrWorkdir -Wait -Verb RunAs
$ServiceName = "UC4.ServiceManager." + $SmgrName
Write-Host "Start Service Manager"
Start-Service -Name $ServiceName

Without ServiceManager

# Create HOST object
Write-Host "Create Agent $($AgentName)"
$ProgressPreference = "SilentlyContinue";
$AgentsUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agents"
$Body = @{
   "name" = $AgentName
   "template" = "AGENT.WEBSERVICEREST"
}
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentsUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 200) {
    throw "Failed to create agent object, status code was " + $result.StatusCode
}

# Download and extract agent package
Write-Host "Create Agent package"
$Body = @{
    "platform" = "RA"
    "name" = $AgentName
    "config_update" = "[GLOBAL]`nname=" + $AgentName
}
$AgentPackUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agentpacks/"
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentPackUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 201) {
    throw "Agent package has not been created, status code was " + $result.StatusCode
}
$AgentZip = $result.Headers['Location']
Write-Host "Download $($AgentZip)"
Invoke-WebRequest -Uri $AgentZip -Credential $Cred -OutFile "tmp.zip"
Expand-Archive -Path "tmp.zip" -DestinationPath $InstallFolder
Remove-Item -Path "tmp.zip"

#Start agent without service manager
Write-Host "Start agent $($AgentName)"
$AgentWorkdir = Join-Path -Path $InstallFolder -ChildPath "agent/bin" -Resolve
Start-Process -FilePath "java" -ArgumentList "-Xmx1024M -jar ucxjcitx.jar" -WorkingDirectory $AgentWorkdir

SQL Agent

The following parameters are used for the SQL examples:

$AgentName = "SQL13"
$SmgrPort = 8873
$SmgrName = "Automic"
$JdbcDrivers = "C:\temp\*jdbc*.jar"
$InstallFolder = "C:\temp\test"
$RestEndpoint = "https://hostname:8088"
$Client = 100
$Cred = Get-Credential

With ServiceManager

# Create HOST object
$ProgressPreference = "SilentlyContinue";
$AgentsUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agents"
$Body = @{
   "name" = $AgentName
   "template" = "<SQL>"  
}
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentsUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 200) {
    throw "Failed to create agent object, status code was " + $result.StatusCode
}

# Download and extract agent package
$Body = @{
    "platform" = "SQL"
    "name" = $AgentName
    "config_update" = "[GLOBAL]`nname=" + $AgentName
    "service_manager" = @{
        "operating_system" = "Windows"
        "operating_system_architecture" = "x64"
        "config_update" = "[GLOBAL]`nport=" + $SmgrPort + "`n[Destination " + $SmgrName + "]`ncmdfile=*OWN\uc4.smc`ndeffile=*OWN\uc4.smd"
    }
}
$AgentPackUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agentpacks/"
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentPackUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 201) {
    throw "Agent package has not been created, status code was " + $result.StatusCode
}
$AgentZip = $result.Headers['Location']
Write-Host "Download " + $AgentZip
Invoke-WebRequest -Uri $AgentZip -Credential $Cred -OutFile "tmp.zip"
Expand-Archive -Path "tmp.zip" -DestinationPath $InstallFolder
Remove-Item -Path "tmp.zip"

#Copy JDBC drivers to agent directory
$AgentJdbc = Join-Path -Path $InstallFolder -ChildPath "agent\bin\jdbc" -Resolve
Copy-Item -Path $JdbcDrivers -Destination $AgentJdbc

#Install and start service manager
$smgrExe = Join-Path -Path $InstallFolder -ChildPath "smgr\bin\ucybsmgr.exe" -Resolve
$SmgrWorkdir = Join-Path -Path $InstallFolder -ChildPath "smgr\bin" -Resolve
$SmgrArguments = "-install " + $SmgrName
Start-Process -FilePath $smgrExe -ArgumentList $SmgrArguments -WorkingDirectory $SmgrWorkdir -Wait -Verb RunAs
$ServiceName = "UC4.ServiceManager." + $SmgrName
Start-Service -Name $ServiceName

Without ServiceManager

# Create HOST object
$ProgressPreference = "SilentlyContinue";
$AgentsUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agents"
$Body = @{
   "name" = $AgentName
   "template" = "<SQL>"
}
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentsUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 200) {
    throw "Failed to create agent object, status code was " + $result.StatusCode
}

# Download and extract agent package
$Body = @{
    "platform" = "SQL"
    "name" = $AgentName
    "config_update" = "[GLOBAL]`nname=" + $AgentName
}
$AgentPackUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agentpacks/"
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentPackUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 201) {
    throw "Agent package has not been created, status code was " + $result.StatusCode
}
$AgentZip = $result.Headers['Location']
Write-Host "Download " + $AgentZip
Invoke-WebRequest -Uri $AgentZip -Credential $Cred -OutFile "tmp.zip"
Expand-Archive -Path "tmp.zip" -DestinationPath $InstallFolder
Remove-Item -Path "tmp.zip"

#Copy JDBC drivers to agent directory
$AgentJdbc = Join-Path -Path $InstallFolder -ChildPath "agent/bin/jdbc" -Resolve
Copy-Item -Path $JdbcDrivers -Destination $AgentJdbc

#Start agent without service manager
$AgentWorkdir = Join-Path -Path $InstallFolder -ChildPath "agent/bin" -Resolve
Start-Process -FilePath "java" -ArgumentList "-jar ucxjsqlx.jar" -WorkingDirectory $AgentWorkdir

Windows Agent

The following parameters are used for the Windows examples:

$AgentName = "WIN13"
$SmgrPort = 8873
$SmgrName = "Automic"
$InstallFolder = "C:\temp\testwin"
$RestEndpoint = "https://hostname:8088"
$Client = 100
$Cred = Get-Credential

With ServiceManager

# Create HOST object
$ProgressPreference = "SilentlyContinue";
$AgentsUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agents"
$Body = @{
   "name" = $AgentName
   "template" = "<WIN>"
}
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentsUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 200) {
    throw "Failed to create agent object, status code was " + $result.StatusCode
}

# Download and extract agent package
$Body = @{
    "platform" = "Windows"
    "name" = $AgentName
    "operating_system_architecture" = "x64"
    "config_update" = "[GLOBAL]`nname=" + $AgentName
    "service_manager" = @{
        "operating_system" = "Windows"
        "operating_system_architecture" = "x64"
        "config_update" = "[GLOBAL]`nport=" + $SmgrPort + "`n[Destination " + $SmgrName + "]`ncmdfile=*OWN\uc4.smc`ndeffile=*OWN\uc4.smd"
    }
}
$AgentPackUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agentpacks/"
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentPackUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 201) {
    throw "Agent package has not been created, status code was " + $result.StatusCode
}
$AgentZip = $result.Headers['Location']
Write-Host "Download " + $AgentZip
Invoke-WebRequest -Uri $AgentZip -Credential $Cred -OutFile "tmp.zip"
Expand-Archive -Path "tmp.zip" -DestinationPath $InstallFolder
Remove-Item -Path "tmp.zip"

#Install and start service manager
$smgrExe = Join-Path -Path $InstallFolder -ChildPath "smgr\bin\ucybsmgr.exe" -Resolve
$SmgrWorkdir = Join-Path -Path $InstallFolder -ChildPath "smgr\bin" -Resolve
$SmgrArguments = "-install " + $SmgrName
Start-Process -FilePath $smgrExe -ArgumentList $SmgrArguments -WorkingDirectory $SmgrWorkdir -Wait -Verb RunAs
$ServiceName = "UC4.ServiceManager." + $SmgrName
Start-Service -Name $ServiceName

Without ServiceManager

# Create HOST object
$ProgressPreference = "SilentlyContinue";
$AgentsUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agents"
$Body = @{
   "name" = $AgentName
   "template" = "<WIN>"
}
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentsUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 200) {
    throw "Failed to create agent object, status code was " + $result.StatusCode
}

# Download and extract agent package
$Body = @{
    "platform" = "Windows"
    "name" = $AgentName
    "operating_system_architecture" = "x64"
    "config_update" = "[GLOBAL]`nname=" + $AgentName + "`nlogon=0"
}
$AgentPackUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agentpacks/"
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentPackUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 201) {
    throw "Agent package has not been created, status code was " + $result.StatusCode
}
$AgentZip = $result.Headers['Location']
Write-Host "Download " + $AgentZip
Invoke-WebRequest -Uri $AgentZip -Credential $Cred -OutFile "tmp.zip"
Expand-Archive -Path "tmp.zip" -DestinationPath $InstallFolder
Remove-Item -Path "tmp.zip"

#Start agent without service manager
$AgentWorkdir = Join-Path -Path $InstallFolder -ChildPath "agent/bin" -Resolve
Start-Process -FilePath "ucxjwx6.exe" -WorkingDirectory $AgentWorkdir

TLS Gateway

The following parameters are used for the TLS Gateway examples:

$AgentName = "TLS_GATEWAY1"
$SmgrPort = 8873
$SmgrName = "Automic"
$InstallFolder = "C:\temp\testtlsgtw"
$RestEndpoint = "https://hostname:8088"
$Client = 100
$Cred = Get-Credential

With ServiceManager

# Create HOST object
Write-Host "Create Agent $($AgentName)"
$ProgressPreference = "SilentlyContinue";
$AgentsUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agents"
$Body = @{
   "name" = $AgentName
   "template" = "AGENT.TLS-GATEWAY"
}
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentsUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 200) {
    throw "Failed to create agent object, status code was " + $result.StatusCode
}

# Download and extract agent package
Write-Host "Create Agent package"
$Body = @{
    "platform" = "TLS_GTW"
    "name" = $AgentName
    "config_update" = "[GLOBAL]`nname=" + $AgentName
    "service_manager" = @{
        "operating_system" = "Windows"
        "operating_system_architecture" = "x64"
        "config_update" = "[GLOBAL]`nport=" + $SmgrPort + "`n[Destination " + $SmgrName + "]`ncmdfile=*OWN\uc4.smc`ndeffile=*OWN\uc4.smd"
    }
}
$AgentPackUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agentpacks/"
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentPackUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 201) {
    throw "Agent package has not been created, status code was " + $result.StatusCode
}
$AgentZip = $result.Headers['Location']
Write-Host "Download $($AgentZip)"
Invoke-WebRequest -Uri $AgentZip -Credential $Cred -OutFile "tmp.zip"
Expand-Archive -Path "tmp.zip" -DestinationPath $InstallFolder
Remove-Item -Path "tmp.zip"

#Install and start service manager
Write-Host "Install Service Manager"
$smgrExe = Join-Path -Path $InstallFolder -ChildPath "smgr\bin\ucybsmgr.exe" -Resolve
$SmgrWorkdir = Join-Path -Path $InstallFolder -ChildPath "smgr\bin" -Resolve
$SmgrArguments = "-install " + $SmgrName
Start-Process -FilePath $smgrExe -ArgumentList $SmgrArguments -WorkingDirectory $SmgrWorkdir -Wait -Verb RunAs
$ServiceName = "UC4.ServiceManager." + $SmgrName
Write-Host "Start Service Manager"
Start-Service -Name $ServiceName

Without ServiceManager

# Create HOST object
Write-Host "Create Agent $($AgentName)"
$ProgressPreference = "SilentlyContinue";
$AgentsUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agents"
$Body = @{
   "name" = $AgentName
   "template" = "AGENT.TLS-GATEWAY"
}
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentsUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 200) {
    throw "Failed to create agent object, status code was " + $result.StatusCode
}

# Download and extract agent package
Write-Host "Create Agent package"
$Body = @{
    "platform" = "TLS_GTW"
    "name" = $AgentName
    "config_update" = "[GLOBAL]`nname=" + $AgentName
}
$AgentPackUrl = $RestEndpoint + "/ae/api/v1/" + $Client + "/system/agentpacks/"
$result = Invoke-WebRequest -Method 'Post' -Uri $AgentPackUrl -Credential $Cred -Body ($Body|ConvertTo-Json) -ContentType "application/json"
if ($result.StatusCode -ne 201) {
    throw "Agent package has not been created, status code was " + $result.StatusCode
}
$AgentZip = $result.Headers['Location']
Write-Host "Download $($AgentZip)"
Invoke-WebRequest -Uri $AgentZip -Credential $Cred -OutFile "tmp.zip"
Expand-Archive -Path "tmp.zip" -DestinationPath $InstallFolder
Remove-Item -Path "tmp.zip"

#Start agent without service manager
Write-Host "Start agent $($AgentName)"
$AgentWorkdir = Join-Path -Path $InstallFolder -ChildPath "agent/bin" -Resolve
Start-Process -FilePath "java" -ArgumentList "-Xmx1024M -jar uctlsgtw.jar" -WorkingDirectory $AgentWorkdir

See also: