# Keeping Your Agent Updated

### Problem <a href="#problem" id="problem"></a>

When configuring the SeaLights agent for DotNet, it isn't easy to manage the agent files in the correct version - especially in standalone environments (containers, backend servers, etc)

### Solution <a href="#solution" id="solution"></a>

The following PowerShell script checks for the recommended agent and latest version, and in case it does not exist locally - downloads & unzips it in the given directory.

#### Downloading the Recommended Agent set in settings <a href="#downloading-the-recommended-agent-set-in-settings" id="downloading-the-recommended-agent-set-in-settings"></a>

{% code overflow="wrap" lineNumbers="true" %}

```powershell
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$previousProgressPref=$global:ProgressPreference
$global:ProgressPreference = "SilentlyContinue" #Disable Progress bar to speed up download and expand

$sldomain="mycompany.sealights.co" #Update with your customer domain
$slToken="$(Get-Content sltoken.txt)" #Prefer a credential Environment variable for the token

Write-Output "Retrieve version from Sealights settings..." 
$slHeader=@{'Accept'='application/json'; 'Authorization'="Bearer $slToken"}
$SLSettingsVersion = ((iwr -Uri https://$sldomain/api/v2/agents/dotnet/recommended -UseBasicParsing -Headers $slHeader).Content | ConvertFrom-Json | Select-Object agent).agent.version

$SLAgentPath=".\SL.DotNet\"
$SlAgentVersionPath = $(Join-Path -Path $SLAgentPath -ChildPath "version.txt")

if( $(Test-Path -Path $SlAgentVersionPath -PathType Leaf) ) 
{
    $SLLocalVersion=Get-Content $SlAgentVersionPath
 
    if ( $SLLocalVersion -eq $SLSettingsVersion )
	{
        Write-Output "Skipping Download - Local agent matches current settings version: $SLLocalVersion"
	} else {
        Write-Output "Local agent is not using the latest version. Deleting local agent."
        Remove-Item -Recurse -Force $SLAgentPath
		#Get-ChildItem -path $SLAgentPath -include * -Recurse -exclude sltoken.txt -erroraction silentlycontinue | Remove-Item -Force -Verbose
	}
}

if( -Not $(Test-Path -Path $SlAgentVersionPath -PathType Leaf) ) 
{
	Write-Output "Download Sealights DotNet agent set in settings..." 
	iwr -OutFile .\sealights-dotnet-agent.zip -UseBasicParsing -Uri http://agents.sealights.co/SL.DotNet/SL.DotNet-$SLSettingsVersion.zip 
	Write-Output "Expanding downloaded archive and placing token..." 
	Expand-Archive .\sealights-dotnet-agent.zip -DestinationPath $SLAgentPath -Force
	Remove-Item -Force .\sealights-dotnet-agent.zip
	Get-ChildItem -Directory -Path .\SL.DotNet\ | Foreach-Object { $slToken | Out-File -NoNewline -Force (Join-Path $_.FullName "sltoken.txt") }
	Write-Output "Sealights agent version used is: $(Get-Content $SlAgentVersionPath)"  
}

#Restore progress bar
$global:ProgressPreference = $previousProgressPref
#End of script
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/troubleshooting-faq/.net-.netcore/keeping-your-agent-updated.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
