Script-Beispiele – Windows

Die folgenden Beispiele zeigen, wie man ein Agentenobjekt (HOST) erstellt, einen Agenten und/oder ein TLS Gateway-Pack herunterlädt und extrahiert und optional den ServiceManager für SQL-, REST- und Windows-Agenten installiert und startet, ebenso wie für das TLS Gateway.

Wichtig! Wenn Sie den ServiceManager installieren und starten möchten, müssen Sie RunAsAdministrator verwenden. Außerdem ist die ServiceManager-Installation nicht gesichert. Weitere Informationen finden Sie unter CAPKI - Sicherung des ServiceManagers.

Diese Seite beinhaltet Folgendes:

REST-Agent

Die folgenden Parameter werden für die REST-Beispiele verwendet:

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

Mit 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

Ohne 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 

Die folgenden Parameter werden für die SQL-Beispiele verwendet:

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

Mit 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

Ohne 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

Die folgenden Parameter werden für die Windows-Beispiele verwendet:

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

Mit 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

Ohne 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

Die folgenden Parameter werden für TLS Gateway-Beispiele verwendet:

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

Mit 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

Ohne 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

Siehe auch: