- Community Home
- >
- Software
- >
- HPE Morpheus Software
- >
- HPE Morpheus Enterprise
- >
- How to Download and Execute Morpheus Agent Script ...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2024 11:24 AM
08-24-2024 11:24 AM
How to Download and Execute Morpheus Agent Script Manually
I’m trying to download the Morpheus agent install script for a specific server and then manually execute it, instead of using the automatic “install agent” process provided by the Morpheus API (as documented here Install Agent).
I am aware that there is a “Download agent script” option in the Morpheus UI, but this endpoint doesn’t seem to be accessible directly through the API, and I’m encountering issues with authentication when trying to download the script manually. My current approach involves testing the download on a Windows server using PowerShell (Invoke-WebRequest and web sessions), but I’m struggling with the correct authentication process.
Is there an alternative or easier way to download the agent script for manual execution? Any guidance or examples would be greatly appreciated.
- Tags:
- agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 03:30 PM
08-28-2024 03:30 PM
Re: How to Download and Execute Morpheus Agent Script Manually
Hey,
as far as I could find out through my own tests, there are 3 things that can be variable in the Install Agent script.
- the API key
- the Morpheus Appiance URL
- the msi name (to be precise the version)
I noticed that when you click on “Download Agent Script” on a Linux server you don’t get the script directly but the following logic:
#!/bin/bash
curl -k -s “$MorpheusApplianceURL/api/server-script/agentInstall?apiKey=$APIKey” | bash
Based on this, I have written the following script that a user can run on his VM to install the agent:
<#
.SYNOPSIS
Dieses Skript überprüft, ob der Morpheus Windows Agent auf einem Windows Server installiert ist.
Falls der Agent nicht installiert ist, wird das Installationsskript von der Morpheus Appliance heruntergeladen und ausgeführt.
.DESCRIPTION
Das Skript führt folgende Schritte aus:
1. Überprüft, ob der Morpheus Windows Agent bereits auf dem Server installiert ist.
2. Ermittelt die Morpheus Appliance URL über einen DNS-Lookup.
3. Fordert den Benutzer auf, seinen Morpheus API-Key einzugeben.
4. Ruft den API-Schlüssel des Servers von der Morpheus Appliance ab.
5. Lädt das Installationsskript des Morpheus Agents herunter und führt es aus, falls der Agent nicht installiert ist.
.PARAMETER ServiceName
Der Name des Windows-Dienstes, der für den Morpheus Agent verwendet wird (Standard: "Morpheus Windows Agent").
.PARAMETER MorpheusURL
Die URL der Morpheus Appliance, die über DNS ermittelt wird.
.PARAMETER MorpheusAPIToken
Der API-Key des Benutzers für die Authentifizierung bei der Morpheus Appliance.
.PARAMETER ServerAPIKey
Der API-Schlüssel des Servers, der von der Morpheus Appliance abgerufen wird.
.EXAMPLE
.\Install-MorpheusWindowsAgent-HyperV.ps1
Überprüft, ob der Morpheus Agent installiert ist, und installiert ihn, falls er nicht vorhanden ist.
.NOTES
Autor: Marvin Lorenz
Version: 1.0
Erstellungsdatum: 29.08.2024
#>
#region Functions
# Funktion zur Überprüfung, ob der Morpheus Agent installiert ist
function Test-MorpheusAgentInstalled {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$ServiceName
)
try {
$service = Get-WmiObject -Class Win32_Service -Filter "Name='$ServiceName'"
return $service -ne $null
}
catch {
Write-Output "Fehler beim Überprüfen, ob der Morpheus Agent installiert ist: $_"
return $false
}
}
# Funktion zur Ermittlung der Morpheus Appliance URL
function Get-MorpheusURL {
try {
$url = "https://" + (Resolve-DnsName -Type CNAME "cloud").Name
return $url
}
catch {
Write-Output "Fehler bei der Ermittlung der Morpheus Appliance URL: $_"
return $null
}
}
# Funktion zur Ermittlung des Server-API-Schlüssels in Morpheus
function Get-MorpheusServerAPIKey {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$MorpheusURL,
[Parameter(Mandatory = $true)]
[string]$MorpheusAPIToken
)
try {
$headers = @{
"accept" = "application/json"
"authorization" = "Bearer $MorpheusAPIToken"
}
try {
$response = Invoke-WebRequest -Uri "$MorpheusURL/api/servers?name=$env:COMPUTERNAME" -Method GET -Headers $headers
} catch {
Write-Error "Fehler beim Abrufen der Serverinformationen aus Morpheus: $_"
Break
}
$ServerInfos = ($response.Content | ConvertFrom-Json).servers
if ($ServerInfos.count -eq 0) {
Write-Output "Es konnte in Morpheus kein Server mit dem Namen $env:COMPUTERNAME gefunden werden."
return $null
}
elseif ($ServerInfos.count -eq 1) {
return $ServerInfos.apiKey
}
elseif ($ServerInfos.count -gt 1) {
$ServerInfo = $ServerInfos | Where-Object { $_.computeServerType.managed -eq "True" }
if ($ServerInfo.count -eq 1) {
return $ServerInfo.apiKey
}
else {
Write-Error "Es konnte in Morpheus kein eindeutiger Server mit dem Namen $env:COMPUTERNAME gefunden werden. Bitte durch das CMP-Team prüfen lassen."
Break
}
}
}
catch {
Write-Error "Fehler bei der Ermittlung des Server-API-Schlüssels in Morpheus: $_"
Break
}
}
# Funktion zum Download und Ausführen des Morpheus Agent Installationsskripts
function Install-MorpheusAgent {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]$MorpheusURL,
[Parameter(Mandatory = $true)]
[string]$ServerAPIKey
)
try {
$response = Invoke-WebRequest -Uri "$MorpheusURL/api/server-script/agentInstall?apiKey=$ServerAPIKey"
$AgentInstallSkript = $response.Content
# Temporäre Datei erstellen
$tempFile = [System.IO.Path]::GetTempFileName() + ".ps1"
# Skriptinhalt in die temporäre Datei schreiben
$AgentInstallSkript | Set-Content -Path $tempFile
# Skript ausführen
Invoke-Expression -Command $tempFile
# Temporäre Datei nach der Ausführung löschen
Remove-Item -Path $tempFile -Force
}
catch {
Write-Error "Fehler beim Installieren des Morpheus Agent: $_"
Break
}
}
#endregion Functions
#region Variables
$ServiceName = "Morpheus Windows Agent"
$MorpheusURL = Get-MorpheusURL
#endregion Variables
#region Main
if (-not $MorpheusURL) {
Write-Output "Morpheus URL konnte nicht ermittelt werden. Skript wird beendet."
exit 1
}
if (Test-MorpheusAgentInstalled -ServiceName $ServiceName) {
Write-Output "Morpheus Agent ist bereits installiert."
exit 0
}
# Morpheus API-Key des Users abfragen
$MorpheusAPIToken = Read-Host "Bitte Ihren Morpheus API-Key eingeben" -AsSecureString
$MorpheusAPIToken = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($MorpheusAPIToken))
$ServerAPIKey = Get-MorpheusServerAPIKey -MorpheusURL $MorpheusURL -MorpheusAPIToken $MorpheusAPIToken
if (-not $ServerAPIKey) {
Write-Output "Server API-Schlüssel konnte nicht ermittelt werden. Skript wird beendet."
exit 1
}
Install-MorpheusAgent -MorpheusURL $MorpheusURL -ServerAPIKey $ServerAPIKey
#endregion Main
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2024 12:48 PM
08-24-2024 12:48 PM
Re: How to Download and Execute Morpheus Agent Script Manually
The only thing that changes between the scripts is the api key for the specific host. You can get the unique api key for the server with this endpoint. Get a Specific Host
Then you would just need to replace the api key in the script.