Skip to content

Commit

Permalink
Update powershell command for hostname detection to avoid profiles an…
Browse files Browse the repository at this point in the history
…d logo that could break detection (#851)

If a Windows system has a powershell profile that emits output, then it
could pollute the output used to read the hostname value. Likewise with
the powershell logo output, though I don't know if/when that logo
appears -- it does not in apm-agent-nodejs' CI tests.

Refs: elastic/apm-agent-nodejs#3899
  • Loading branch information
trentm authored Mar 12, 2024
1 parent 149cd3e commit 44f3ba3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion specs/agents/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var hostname;
if os == windows
// https://stackoverflow.com/questions/12268885/powershell-get-fqdn-hostname
// https://learn.microsoft.com/en-us/dotnet/api/system.net.dns.gethostentry
hostname = exec "powershell.exe [System.Net.Dns]::GetHostEntry($env:computerName).HostName" // or any equivalent *
hostname = exec "powershell.exe -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command [System.Net.Dns]::GetHostEntry($env:computerName).HostName" // or any equivalent *
if (hostname == null || hostname.length == 0)
hostname = exec "cmd.exe /c hostname" // or any equivalent *
if (hostname == null || hostname.length == 0)
Expand Down

0 comments on commit 44f3ba3

Please sign in to comment.