@hondaru2004, here's a powershell script that will create a new computer in your TRIGGERcmd account. It assumes you installed the agent on the master PC you cloned because it uses the token.tkn file from that install for authentication. It writes the computer ID and computer name to the config files in the user's home directory. I hope this helps.
# === Configuration ===
$urlprefix = "https://triggercmd.com"
$computername = $env:COMPUTERNAME
# Read token from TRIGGERcmd token file
$tokenPath = Join-Path $env:USERPROFILE ".TRIGGERcmdData\token.tkn"
if (Test-Path $tokenPath) {
$token = Get-Content $tokenPath -Raw | ForEach-Object { $_.Trim() }
Write-Host "Token loaded from: $tokenPath" -ForegroundColor Green
} else {
Write-Host "Error: Token file not found at $tokenPath" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
# === Perform the POST request ===
Write-Host "Making API request..." -ForegroundColor Green
$headers = @{
"Authorization" = "Bearer $token"
"Content-Type" = "application/x-www-form-urlencoded"
}
$body = "name=$computername"
try {
$response = Invoke-RestMethod -Uri "$urlprefix/api/computer/save" -Method POST -Headers $headers -Body $body
# === Display the full response ===
Write-Host "`nAPI Response:" -ForegroundColor Yellow
$response | ConvertTo-Json -Depth 10 | Write-Host
# === Extract and save the ID ===
$computerId = $response.data.id
if ($computerId) {
# Save ID to TRIGGERcmd config file
$computerIdPath = Join-Path $env:USERPROFILE ".TRIGGERcmdData\computerid.cfg"
$computerNamePath = Join-Path $env:USERPROFILE ".TRIGGERcmdData\computername.cfg"
# Ensure the directory exists
$triggerCmdDir = Split-Path $computerIdPath -Parent
if (!(Test-Path $triggerCmdDir)) {
New-Item -ItemType Directory -Path $triggerCmdDir -Force | Out-Null
}
# Save ID to file
$computerId | Out-File -FilePath $computerIdPath -Encoding ASCII -NoNewline
# Save computer name to file
$computername | Out-File -FilePath $computerNamePath -Encoding ASCII -NoNewline
Write-Host "`nExtracted ID: $computerId" -ForegroundColor Cyan
Write-Host "ID saved to: $computerIdPath" -ForegroundColor Green
Write-Host "Computer name saved to: $computerNamePath" -ForegroundColor Green
} else {
Write-Host "`nError: Could not find ID in response" -ForegroundColor Red
}
} catch {
Write-Host "`nError making API request:" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
}
Write-Host "`nRequest completed." -ForegroundColor Green
Run the script with a command like this:
powershell -ExecutionPolicy Bypass -File .\change_tcmd_id.ps1
Or, you could just delete the computerid.cfg file and it will prompt you for the token like when you first install the agent.







