updat
This commit is contained in:
@@ -1,23 +1,48 @@
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[string]$AGENT_URL,
|
||||
[int]$CUSTOMER_ID,
|
||||
[int]$SOFTWARE_ID=101,
|
||||
[string]$AGENT_FILENAME='EmberkomAgentSetup.exe'
|
||||
)
|
||||
|
||||
## Immediately delete this script from disk
|
||||
Try { Remove-Item $MyINvocation.InvocationName -Force }
|
||||
Catch { Write-Output "This script tried to delete itself but failed!" }
|
||||
|
||||
## Build the path for $AGENT_INSTALLER
|
||||
$TEMP = [System.IO.Path]::GetTempPath()
|
||||
$AGENT_INSTALLER = "${TEMP}\${AGENT_FILENAME}"
|
||||
|
||||
## Make sure the AGENT_URL is specified
|
||||
If ( $AGENT_URL )
|
||||
## Make sure the CUSTOMER_ID is specified
|
||||
If ( $CUSTOMER_ID )
|
||||
{
|
||||
## Make sure we need to install the agent
|
||||
If ( !(Test-Path 'HKLM:SOFTWARE\N-able Technologies\NcentralAsset') -and !(Test-Path 'SOFTWARE\Wow6432Node\N-able Technologies\NcentralAsset'))
|
||||
{
|
||||
## Download the agent
|
||||
If ( Test-Path $AGENT_INSTALLER ) { Remove-Item $AGENT_INSTALLER -Force }
|
||||
(New-Object System.Net.WebClient).DownloadFile("${AGENT_URL}", $AGENT_INSTALLER)
|
||||
## Build the AGENT_URL
|
||||
$AGENT_URL = "{0}{1}{2}{3}" -f 'https://manage.emberkom.com/dms/FileDownload?customerID=',$CUSTOMER_ID.ToString(),'&softwareID=',$SOFTWARE_ID.ToString()
|
||||
|
||||
## Delete $AGENT_INSTALLER if it already exists
|
||||
If ( Test-Path $AGENT_INSTALLER )
|
||||
{
|
||||
Try { Remove-Item $AGENT_INSTALLER -Force }
|
||||
Catch { Write-Output "The agent installer already exists but there was an error when trying to delete it!" }
|
||||
}
|
||||
|
||||
## Download the agent installer
|
||||
Try { (New-Object System.Net.WebClient).DownloadFile($AGENT_URL, $AGENT_INSTALLER) }
|
||||
Catch { Write-Output "There was an error downloading the agent installer!"; Exit }
|
||||
|
||||
## Install the agent
|
||||
Start-Process $AGENT_INSTALLER -ArgumentList '/quiet /passive' -Wait
|
||||
}
|
||||
}
|
||||
Try { Start-Process $AGENT_INSTALLER -ArgumentList '/quiet /passive' -Wait }
|
||||
Catch { Write-Output "There was an error installing the agent!" }
|
||||
New-Item -Path $Env:SYSTEMDRIVE -Name "ready-for-install" -ItemType "file" -Value ""
|
||||
|
||||
## Remove the agent installer
|
||||
If ( Test-Path $AGENT_INSTALLER )
|
||||
{
|
||||
Try { Remove-Item -Path $AGENT_INSTALLER -Force }
|
||||
Catch { Write-Output "There was an error while deleting the agent installer!" }
|
||||
}
|
||||
} Else { Write-Output "The agent is already installed on this endpoint." }
|
||||
} Else { Write-Output "No CUSTOMER_ID was specified!" }
|
||||
|
||||
Reference in New Issue
Block a user