@echo off net session >nul 2>&1 if %errorlevel% neq 0 ( powershell -NoProfile -Command "Start-Process -FilePath '%~f0' -Verb RunAs" exit /b ) powershell -NoProfile -ExecutionPolicy Bypass -Command "$t = Get-Content -Raw -LiteralPath '%~f0'; $i = $t.IndexOf('#'+'PSSTART'); Invoke-Expression $t.Substring($i)" echo. pause exit /b #PSSTART $ErrorActionPreference = 'Stop' $base = 'https://security.planb.org.in' Write-Host '' Write-Host '=== PlanB Agent Setup ===' -ForegroundColor Cyan $code = Read-Host 'Enter your company enrollment code (sent by your administrator)' $code = ($code -replace '[^A-Za-z0-9_-]', '') if (-not $code) { Write-Host 'No code entered. Run this file again.' -ForegroundColor Red; return } $dir = 'C:\Program Files (x86)\PlanBAgent' if (-not (Test-Path "$dir\PlanBAgent.exe")) { $tmp = "$env:TEMP\PlanB-Agent-Setup.exe" Write-Host 'Downloading agent (about 170 MB), please wait...' [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri "$base/downloads/PlanB-Agent-Setup.exe" -OutFile $tmp -UseBasicParsing Write-Host 'Installing agent...' Start-Process -FilePath $tmp -ArgumentList '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' -Wait | Out-Null Remove-Item $tmp -Force -ErrorAction SilentlyContinue } if (-not (Test-Path "$dir\PlanBAgent.exe")) { Write-Host 'Install failed: agent not found.' -ForegroundColor Red; return } $p = "$dir\appsettings.json" if (-not (Test-Path ($p + '.bak'))) { Copy-Item $p ($p + '.bak') -Force } Get-Process -Name PlanBAgent -ErrorAction SilentlyContinue | Stop-Process -Force Start-Sleep -Seconds 2 $j = Get-Content $p -Raw | ConvertFrom-Json function SetP($o, $n, $v) { if ($o.PSObject.Properties[$n]) { $o.$n = $v } else { $o | Add-Member -NotePropertyName $n -NotePropertyValue $v } } SetP $j.PlanB 'ApiBaseUrl' 'https://security.planb.org.in' SetP $j.PlanB 'EnrollCode' $code SetP $j.PlanB 'ReverbHost' 'ws-ap2.pusher.com' SetP $j.PlanB 'ReverbPort' 443 SetP $j.PlanB 'ReverbKey' '0a76efbd512fe1b1bed0' SetP $j.PlanB 'ReverbUseSsl' $true $j | ConvertTo-Json -Depth 5 | Set-Content $p -Encoding UTF8 Start-ScheduledTask -TaskName 'PlanBAgent' $cfg = Get-Content $p -Raw | ConvertFrom-Json if ($cfg.PlanB.EnrollCode -eq $code -and $cfg.PlanB.ReverbHost -eq 'ws-ap2.pusher.com') { Write-Host 'Done. Settings saved and the agent restarted. It will appear in the dashboard within 1-2 minutes.' -ForegroundColor Green } else { Write-Host 'Failed: the code was not saved. Contact your administrator.' -ForegroundColor Red }