Error in the below code

Manideep Ramini 0 Reputation points
2025-06-13T06:42:22.0766667+00:00

Hi All,

Could you identify what is the error in the below code.

wget "https://download-files.appdynamics.com/download-file/machine-bundle/25.1.0.4532/machineagent-bundle-64bit-windows-25.1.0.4532.zip?Expires=1749724358&Signature=jN7t4pNj8-fUSyG4jXQShRNJuyKDJiEszevDFQUN2jP5Mi5YTI9RUeORGOFCxqC0kGyyS~3KdGpFX3GXgDD3Wd~xH4rdOJhPUuy4Cr1B2WGwXwhEKT1okLSW0OfChX8NKwaqwyMjNmOEJbFI43kJimozo6nwZ-~bx-HTphJsx7om7XP7LdYTJJ7KEFUegwoo2H~rW3-Je~AQuk4SNG8b~LBjO8kf3R6gEtQuVeHr6i31uenUvFulpPG4vxxZz3LMysBYN0e5nPWKic7nWuSHSz3qOLk3Qi2dcbIE-QOhhFi~EKXv-zwuOVEE3sj~9~sCZTbneGcSxofc7sQOk1mLTg__&Key-Pair-Id=APKAI6PWCU7XQZAIYFCA" -OutFile "C:\machine-agent-25.1.zip"

Expand-Archive C:\machine-agent-25.1.zip -DestinationPath C:\machine-agent-25.1

Path to the controller-info.xml file

$xmlPath = "C:\machine-agent-25.1\conf\controller-info.xml"

Load the XML

[xml]$xml = Get-Content $xmlPath

Get the <controller-info> node

$controllerInfo = $xml.SelectSingleNode("//controller-info")

$maHome = "C:\machine-agent-25.1"

$keystorePath = "$maHome\secretKeyStore"

$storePass = "MyCredentialStorePassword"

$accessKey = "XXXXXXX"

$jarPath = "$maHome\lib\secure-credential-store-tool-1.3.23.jar"

Step 1: Create KeyStore

& "$maHome\jre\bin\java.exe" -jar $jarPath generate_ks -filename $keystorePath -storepass $storePass

Step 2: Obfuscate store password

$obfuscatedPass = & "$maHome\jre\bin\java.exe" -jar $jarPath obfuscate -plaintext $storePass

Step 3: Encrypt AccessKey

$encryptedKey = & "$maHome\jre\bin\java.exe" -jar $jarPath encrypt -filename $keystorePath -storepass $storePass -plaintext $accessKey

function Set-Or-CreateTag {

param (

    [System.Xml.XmlElement]$parent,

    [string]$tagName,

    [string]$tagValue,

    [System.Xml.XmlDocument]$doc

)

$tag = $parent.SelectSingleNode($tagName)

if (-not $tag) {

    $tag = $doc.CreateElement($tagName)

    $tag.InnerText = $tagValue

    $parent.AppendChild($tag) | Out-Null

} else {

    $tag.InnerText = $tagValue

}

}

Set-Or-CreateTag -parent $controllerInfo -tagName "controller-host" -tagValue "XXXXX" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "controller-port" -tagValue "XXXX" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "controller-ssl-enabled" -tagValue "true" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "agent-runtime-dir" -tagValue "true" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "use-encrypted-credentials" -tagValue "true" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "credential-store-filename" -tagValue "C:\machine-agent-25.1\secretKeyStore" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "credential-store-password" -tagValue "$obfuscatedPass" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "account-access-key" -tagValue "$encryptedKey" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "account-name" -tagValue "XXXXX" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "sim-enabled" -tagValue "true" -doc $xml

Set-Or-CreateTag -parent $controllerInfo -tagName "dotnet-compatibility-mode" -tagValue "false" -doc $xml

#Set-Or-CreateTag -parent $controllerInfo -tagName "application-name" -tagValue "XXXX" -doc $xml

#Set-Or-CreateTag -parent $controllerInfo -tagName "tier-name" -tagValue "XXXX" -doc $xml

#Set-Or-CreateTag -parent $controllerInfo -tagName "node-name" -tagValue "XXXX" -doc $xml

Save the updated XML

$xml.Save($xmlPath)

Write-Host "Tags updated successfully in controller-info.xml"

#Installing the Machine Agent and starting the Service

Start-Process "wscript.exe" -ArgumentList '"C:\machine-agent-25.1\InstallServiceWrapper.vbs"' -Verb RunAs

Start-Sleep -Seconds 60

Start-Service -Name "Appdynamics Machine Agent"

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,970 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.