Powershell Script for windows grafana agent on custom directory

I am trying to build a PowerShell script to install the Grafana agent on windows in a custom path and not in C drive. However I am not able to change the installation path since I do not which parameter do I need to pass and it is also not mentioned on the documentation.

Sample code:

$URL = "https://github.com/grafana/agent/releases/latest/download/grafana-agent-installer.exe"

$DIR = "D:\Grafana-Agent1\"

$FILE = "$DIR\grafana-agent-installer.exe"

if (-not(Test-Path -Path $DIR)) {
     try {
        New-Item -Path $DIR -ItemType Directory
    }
    catch {
         throw $_.Exception.Message
     }
} else {
  Write-Output ("Path already exist")
}

if (-not(Test-Path -Path $FILE -PathType Leaf)) {
     try {
         $wc = new-object System.Net.WebClient
         $wc.DownloadFile("$URL","$DIR\grafana-agent-installer.exe")
         Write-Output ("The file has been downloaded")
     }
     catch {
         throw $_.Exception.Message
     }
 } else{
	 Remove-Item -Path $FILE -Recurse
     Write-Output ("Old File has been removed")
     try {
         $wc = new-object System.Net.WebClient
         $wc.DownloadFile("$URL","$DIR\grafana-agent-installer.exe")
         Write-Output ("The file has been downloaded")
     }
     catch {
         throw $_.Exception.Message
     }
}

Hi @kunalkhandagale1,

Welcome to the :grafana: community support forums !!

Well :slight_smile: I am not a Windows user so unfortunately cannot help much but I will suggest to just for it on the Internet and I think you will find the correct syntax to change the directory (I know these questions are v.commonly asked on websites e.g. stackoverflow etc).

I am sure other communtly users will be also to help you out.

I am not getting the exact command on internet as well. May be that exe does not support the install directory parameter.
I have tried to implement the below workaround but also did not work

Installed the grafana agent on C drive by default.
Moved the configuration from C drive to D drive
Executed the below command as per Grafana Documentation:
sc.exe config “Grafana Agent” binpath= “D:\Program Files\Grafana Agent\agent-windows-amd64.exe -config.file="D:\Program Files\Grafana Agent\agent-config.yaml"”

However when I tried to start the service I am getting the below error

image