Operation on VMware virtual PCs
-
If a master PC VM is created and then copied and deployed, it seems that all PCs have the same computer ID, causing conflicts and preventing them from working correctly. For example, with TriggerCMD, it appears to only refer to the commands of the PC where it was started last, and it doesn’t work on all VMs. Is there any workaround for this?
-
@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 GreenRun the script with a command like this:
powershell -ExecutionPolicy Bypass -File .\change_tcmd_id.ps1