-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall ConnectSecure Agent.ps1
More file actions
30 lines (27 loc) · 1.2 KB
/
Copy pathInstall ConnectSecure Agent.ps1
File metadata and controls
30 lines (27 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Prefer environment variables, fallback to hardcoded values if needed
$cybercnscompany_id = (Ninja-Property-Get connectsecureCompanyId)
$cybercnstenantid = '' # populate from CS website
$cybercnstoken = '' # populate from CS website
$serviceName = 'cybercnsagent'
# Confirm company ID is provided
if (-not $cybercnscompany_id) {
return "cybercnscompany_id is NULL"
}
# Check if the service already exists
$svc = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
if ($svc) {
# Service found - check if it's running
if ($svc.Status -eq 'Running') {
return "$serviceName found and running."
} else {
return "$serviceName found, but it is not running."
}
} else {
# Service not found - download and install the agent
$source = (Invoke-RestMethod -Method "Get" -URI "https://configuration.myconnectsecure.com/api/v4/configuration/agentlink?ostype=windows")
$destination = 'cybercnsagent.exe'
# Download the agent executable
Invoke-WebRequest -Uri $source -OutFile $destination
# Run the installer with company credentials and tenant information
& .\cybercnsagent.exe -c $cybercnscompany_id -e $cybercnstenantid -j $cybercnstoken -i
}