Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Use this function to add a computer to a computer group.

Note 1: Ensure that the computer group is created in the UI with at least one device included before running the command.

Note 2: The device name should be added exactly as it appears in the UI, without the FQDN, and the device must have reported to the GYTPOL console previously. Devices that have never reported cannot be added.

Request Structure

groupName

string

Mandatory

Group name

computerName

string

Mandatory

Computer name, case-insensitive

...

Code Block
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("x-api-key", "{API KEYx-api-key}")
$headers.Add("Content-Type", "application/json")

$body = "{‘groupName’: ‘{GROUP}’, computerName: ‘{COMPUTER}’}"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

$response = Invoke-RestMethod -uri "https://{BASE-URL}/gytpolapi/v2.0/add_to_group" -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

...

Code Block
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("x-api-key", "{APIKEYx-api-key}")
$headers.Add("Content-Type", "application/json")

# Ensure the computer group is created in the UI with at least one device
# Replace {GROUP} with the actual group name, i.e SERVERS
$groupName = "{GROUP}"

# Read computer names from CSV file without headers
$computers = Get-Content -Path "c:\path\to\computers.csv" | Select-Object -Skip 1

# Loop through each computer and add it to the group
foreach ($line in $computers) {
    # Split the line by commas and take the first part as the computer name
    $computerName = $line.Split(',')[0].Trim()

    # Create the body for the API request
    $body = @{
        groupName = $groupName
        computerName = $computerName
    } | ConvertTo-Json
    
    # Send the API request
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    
    $response = Invoke-RestMethod -Uri "https://{BASEURLBASE-URL}/gytpolapi/v2.0/add_to_group" -Method 'POST' -Headers $headers -Body $body
    $response | ConvertTo-Json
}

...