TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Operation on VMware virtual PCs

    General Discussion
    2
    2
    16
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      hondaru2004
      last edited by

      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?

      RussR 1 Reply Last reply Reply Quote 0
      • RussR
        Russ @hondaru2004
        last edited by Russ

        @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

        Russell VanderMey

        1 Reply Last reply Reply Quote 0
        • First post
          Last post