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
}
}