Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

Using Powershell to get the latest Server Agent

powershell
servers
windowsserver

#1

I thought I would share this with the community because it seemed that the information was not 100% obvious. Thanks to NR team for having this link available. The good news is that if you use this method you don’t have to search for the latest version.

New Relic offers a short link that is always the latest version of the Server Agent.
http://download.newrelic.com/windows_server_monitor/release/

In this S3 bucket you will find a link to X86 and X64. The links do not have an extension.
You can use powershell to make a web call to get that version and save it as the filename with extension you specify.
Invoke-WebRequest -uri ‘http://download.newrelic.com/windows_server_monitor/release/x64’ -outfile ‘newrelicServerMonitor_x64.msi’

This is very helpful because then you don’t need to “find” the latest version of the software. Although this seems obvious now it was not obvious at first glance because it almost looked like a folder not a file. I had to actually download it, append the extension and test if it was the latest version.

thanks for offering this method.

PS. If you want the full script including Functions you can see it here:

function Is-Current-User-Admin() {
return ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] “Administrator”)
}

function write-event($source, $eventid, $entrytype, $message) {
$SourceExists = [System.Diagnostics.EventLog]::SourceExists(“New Relic Agent Install”)
if (! $SourceExists) {
New-EventLog -LogName Application -Source “New Relic Agent Install”
}

write-host "source: ", $source, "eventid: ", $eventid, "message: ", $message  
Write-EventLog –LogName Application –Source $source –EntryType $entrytype –EventID $eventid –Message $message  

}

function check_temp_new_relic_path(){
if (!(test-path -path $pathname)) {
new-item -ItemType directory -Path $pathname -force
}
if (!(test-path $pathname)){
write-message “Could not create c:\temp\new_relic_agent. Please check manually”
}

$message = 'Ran the check_temp_new_relic_path Function'  
write-event -source 'New Relic Agent Install' -eventid '7020' -entrytype 'Information' -message $message  
return   

}

function download_files(){
if (!(test-path -path $pathname)) {
new-item -ItemType directory -Path $path -force
}
cd $pathname
$output = Invoke-WebRequest -uri ‘http://download.newrelic.com/windows_server_monitor/release/x64’ -outfile ‘newrelicServerMonitor_x64.msi’
write-host $output
}

function Install-MSIFile {
{Param (
[string]$msiFile,
[string]$pathName,
[string]$newRelicLicensekey
);
}
$fullpath = $pathName+$msiFile

$arguments = @(
“/i”
"$fullPath”"
“/qn AcceptEndUserLicenseAgreement=1”
“/norestart”
“/lv c:\temp\new_relic_agent\install.log”
“USE_SETTINGS_FROM_AD=1”
“NR_LICENSE_KEY=” + $newRelicLicenseKey
“NR_PROXY_ADDRESS=proxy-us.intel.com:911
)

write-host $arguments

if ($targetDir){
if (!(Test-Path $targetDir)){
throw “Path to the Installation Directory $($targetDir) is invalid. Please supply a valid installation directory”
}
$arguments += “INSTALLDIR="$targetDir”"
}

Write-Verbose “Installing $msiFile…”
$process = Start-Process -FilePath msiexec.exe -ArgumentList $arguments -Wait -PassThru
if ($process.ExitCode -eq 0){
Write-Verbose “$msiFile has been successfully installed”
}
else {
Write-Verbose “installer exit code $($process.ExitCode) for file $($msifile)”
}
}

function clean_temp_files($msiFile){
if (test-path $pathName){
write-host “finding path”
$file = Get-ChildItem -Path $msiFile
remove-item $file
set-location -path c:\temp
get-location
remove-item -path $pathName
}
$message = ‘Ran the clean_temp_files Function’
write-event -source ‘New Relic Agent Install’ -eventid ‘7029’ -entrytype ‘Information’ -message $message
return
}

function CheckAgentVersion() {
$rtn = get-wmiobject win32_operatingsystem -computer localhost | select-object -expandproperty OSArchitecture
write-host “Returning X64Version” $rtn
if(!($rtn = ‘64-bit’)){
write-host “This is only for 64bit systems”
exit
}
return $rtn
}

function get-nr-license-key {
$newRelicLicenseKey = read-host ‘Input your License key’
return $newRelicLicenseKey
}

Variables

$msiFile = ‘newrelicServerMonitor_x64.msi’
$pathName = ‘c:\temp\new_relic_agent’

system Checks

$isAdmin = Is-Current-User-Admin
CheckAgentVersion

Prompt user for NR License Key

$newRelicLicenseKey = get-nr-license-key

Functions

check_temp_new_relic_path
download_files
Install-MSIFile -msiFile $msiFile -newRelicLicenseKey $newRelicLicenseKey
clean_temp_files


[Datanaut Challenge] Share your tips, tricks and best practices
Feature Idea: .Net APM Agent w3wp process not found
#2

Hey John! I just wanted to thank you for sharing this here where everyone can benefit from your great work. Thanks for being such an excellent community member.


#3

This is the old monitor. The new stuff is split in two for Windows:
Latest DotNet Agent:
http://download.newrelic.com/dot_net_agent/latest_release/NewRelicDotNetAgent_x64.msi

Latest Infrastructure agent:
http://download.newrelic.com/infrastructure_agent/windows/newrelic-infra.msi

I am working on a PowerShell DSC module to do the install of these agents. And the “Server_Monitor” stuff obsolete (I believe).


#4

Yup - thanks for that @fpostle, you’re right. Legacy server agents are deprecated now. Infrastructure is the replacement tool for server monitoring.