Security Controls REST API

Home 

Exercise 2 - Create a Machine Group

Goal

Create a machine group consisting of several machines contained in your domain. The credential that you created in Exercise 1 will be used to access the machines in the group.

Requirement

You will need the unique ID of the new credential that you created in Exercise 1. You can determine the ID by looking in the output from Exercise 1.

Try it yourself

Create a new machine group named Sample Group that consists of three machines by submitting a POST request similar to the following:

In the DiscoveryFilters section, change the machine names (SampleMachineA, SampleMachineB, SampleMachineC) as needed.

Postman example

        https://localhost:3121/st/console/api/v1.0/machinegroups
        {
        "name":"Sample Group",
        "description":"This is a sample group created using the REST API",
        "credentialId":"ce45a98c-e8f0-4f88-a972-d66f99a9ef03",
        "discoveryFilters":[{
        "category":"MachineName",
        "name":"SampleMachineA",
        "isExcluded":"False"
        },
        {
        "category":"MachineName",
        "name":"SampleMachineB",
        "isExcluded":"False"
        },
        {
        "category":"MachineName",
        "name":"SampleMachineC",
        "isExcluded":"False"
        }]
        }
		

PowerShell script example

        $id = "ce45a98c-e8f0-4f88-a972-d66f99a9ef03"
        $machineGroupUrl = "https://localhost:3121/st/console/api/v1.0/machinegroups"
        $machineGroupBody =
        @{
        name = "Sample Group"
        discoveryFilters = @(
        @{
        AdminCredentialId = $id;
        category = "MachineName";
        name = "SampleMachineA"
        },
        @{
        AdminCredentialId = $id;
        category = "MachineName";
        name = "SampleMachineB"
        })
        } | ConvertTo-Json -Depth 99
        Invoke-RestMethod -Method Post -Credential $credential -URI $machineGroupUrl -Body $machineGroupBody -ContentType "application/json" | ConvertTo-Json -Depth 20
        

Output

The result is a JSON-formatted response similar to the following:

		{
		"creator": "SHAVLIK\\joe.coder",
		"credentialId": "ce45a98c-e8f0-4f88-a972-d66f99a9ef03",
		"description": "This is a sample group created using the REST API",
		"id": 1006,
		"isBuiltIn": false,
		"isReadOnly": false,
		"links": {
		"self": {
		"href": "https://device-name.fakedomain.com:3121/st/console/api/v1.0/machinegroups/1006"
		},
		"discoveryfilters": {
		"href": "https://device-name.fakedomain.com:3121/st/console/api/v1.0/machinegroups/1006/discoveryfilters"
		},
		"virtualmachinediscoveryfilters": {
		"href": "https://device-name.fakedomain.com:3121/st/console/api/v1.0/machinegroups/1006/virtualmachinediscoveryfilters"
		},
		"usedby": {
		"href": "https://device-name.fakedomain.com:3121/st/console/api/v1.0/machinegroups/1006/usedby"
		}
		},
		"name": "Sample Group",
		"serverFilterTypes": "All"
		}
			

 


Was this article useful?    

The topic was:

Inaccurate

Incomplete

Not what I expected

Other