Computer by Name Filter

For computer groups that do not employ Active Directory services to identify computers, the Filter by Name filter rule can be used to identify computers using any of three identification methods:

  • manual entry
  • copy from a spreadsheet
  • populate and manage from an API

These instructions step through the Filter by Name feature that is used to create filters for computer groups using computer names.

Creating a Computer Name Filter Collection Query

These queries are dependent on the admin role a user might have. Verify Privilege Manager Administrators can create new collections on the Collections root level. Verify Privilege Manager macOS, Unix/Linux, or Windows Administrators must select the OS specific folder from the Collections tree.

  1. Navigate to Admin | Resources and select the Resource Filters tab.
  2. From the Resource Filters tree, select Collections.
  3. Click Create.

    alt

  1. From the Template drop-down, select Computers by Name Filter.
  2. Enter a name and edit the description to better identify the purpose of the resource you are creating.

    alt

  1. The Details page for the newly created collection is displayed. Three options are available for entering names in the Computer Names field: enter names manually, paste in entries from an Excel spreadsheet, or use the API to populate names.

    To use the API method, refer to the instructions for Populating Computer Names using the API after these instructions. Proceed to create a rule for the named filter in the designated computer group next.

    alt

  1. Navigate to the Computer Group that will be associated with the newly created filter.
  2. On the Details page for that computer group, click Add Rule.
  3. Specify a Collection as the LIST TYPE. Select the newly created filter in the SELECTED ITEMS drop-down.
  4. Click Save Changes.

    alt

  1. Proceed with the instructions for Populating Computer Names using the API.

Populating Computer Names using the API

Below is an example of a PowerShell script that is used to populate computer names.

To create your script, use the By Name Filters methods presented in the Verify Privilege Manager API.

The API script can be run at your discretion at any time computer names need to be refreshed.

Example PowerShell Script

The example PowerShell script incorporates API methods that includes Create-ComputersByNameFilter. In practice, this is not required for subsequent script executions. Instead, use one of the API mthods to update the list and get $filterId from the item ID shown in the browser URL when viewing the Computers by Name filter created in the first step.

In this example,

  • $api_user_clientid and $api_user_secret are obtained from the Admin | Users page for that user.
  • client ID and secret are obtained from the Details page for that user.
Copy
# Computers By Name Filter Test Script #
$api_user_clientid = ''
$api_user_secret = ''
$tmsBaseUri = 'https://localhost/Tms'
$tmsAPIBaseUri = "$tmsBaseUri/services/api"
$tmsAPIAuthUri = "$tmsAPIBaseUri/logon/token"
$tmsAPIByNameFiltersUri = "$tmsAPIBaseUri/v1/bynamefilters"
$tmsAPIContentType = 'application/json'
$tmsAPIBearerToken = $null;
# Functions
function Ignore-SSLCertificateErrors
{
    if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
    {
        $certCallback = @"
            using System;
            using System.Net;
            using System.Net.Security;
            using System.Security.Cryptography.X509Certificates;
            public class ServerCertificateValidationCallback
            {
                public static void Ignore()
                {
                    if(ServicePointManager.ServerCertificateValidationCallback ==null)
                    {
                        ServicePointManager.ServerCertificateValidationCallback += 
                            delegate
                            (
                                Object obj, 
                                X509Certificate certificate, 
                                X509Chain chain, 
                                SslPolicyErrors errors
                            )
                            {
                                return true;
                            };
                    }
                }
            }
"@
        Add-Type $certCallback
    }
    [ServerCertificateValidationCallback]::Ignore()
}
function Read-ResponseJson
{
    param ([Microsoft.PowerShell.Commands.WebResponseObject] $response)
    if($response.StatusCode -lt 200 -or $response.StatusCode -gt 299)
    {
        throw "Request failed with error code: $($response.StatusCode): $($response.StatusDescription)"
    }
    ConvertFrom-Json $response.Content        
}
function Authenticate-APIUser
{
    if($tmsAPIBearerToken -eq $null)
    {
        $body = "{ ""username"": ""$api_user_clientid"", ""password"": ""$api_user_secret"" }"
        $response = Invoke-WebRequest -Uri $tmsAPIAuthUri -Body $body -ContentType $tmsAPIContentType -Method Post
        $tmsAPIBearerToken = Read-ResponseJson -response $response
    }
    $tmsAPIBearerToken
}
function Invoke-APIRequest
{
    param ([string]$uri, [string]$body, [Microsoft.PowerShell.Commands.WebRequestMethod] $method)
    $bearerToken = Authenticate-APIUser
    $headers = @{Authorization="Bearer $bearerToken"}
    if(-not $body)
    {
        $response = Invoke-WebRequest -Uri $uri -Method $method -Headers $headers 
    }
    else
    {
        $response = Invoke-WebRequest -Uri $uri -Method $method -Body $body -ContentType "application/json" -Headers $headers
    }
    Read-ResponseJson -response $response
}
function Create-ComputersByNameFilter
{
    param ([string]$name, [string]$description, [string]$names)
    $body = "{ ""Name"": ""$name"", ""Description"": ""$description"", ""Names"": ""$names"" }"
    $response = Invoke-APIRequest -uri "$tmsAPIByNameFiltersUri/new" -body $body -method Post
    $response
}
function Add-ComputersByNameToFilter
{
    param ([Guid]$filterId, [string]$names)
    $body = "{ ""Names"": ""$names"" }"
    $response = Invoke-APIRequest -uri "$tmsAPIByNameFiltersUri/$filterId/add-names" -body $body -method Post
    $response
}
function Remove-ComputersByNameToFilter
{
    param ([Guid]$filterId, [string]$names)
    $body = "{ ""Names"": ""$names"" }"
    $response = Invoke-APIRequest -uri "$tmsAPIByNameFiltersUri/$filterId/remove-names" -body $body -method Post
    $response
}
function Set-ComputersByNameToFilter
{
    param ([Guid]$filterId, [string]$names)
    $body = "{ ""Names"": ""$names"" }"
    $response = Invoke-APIRequest -uri "$tmsAPIByNameFiltersUri/$filterId/names" -body $body -method Post
    $response
}
function Get-ComputersByNameFromFilter
{
    param ([Guid]$filterId)
    $response = Invoke-APIRequest -uri "$tmsAPIByNameFiltersUri/$filterId/names" -body $body -method Get
    $response
}
function Get-ComputersByNameFromFilterAsCsv
{
    param ([Guid]$filterId)
    $response = Invoke-APIRequest -uri "$tmsAPIByNameFiltersUri/$filterId/namescsv" -body $body -method Get
    $response
}
function Get-ComputersByNameFromFilterAsLines
{
    param ([Guid]$filterId)
    $response = Invoke-APIRequest -uri "$tmsAPIByNameFiltersUri/$filterId/namesnewline" -body $body -method Get
    $response
}
Ignore-SSLCertificateErrors
# Create a new filter
$response = Create-ComputersByNameFilter -name "Test Computers by Name From API" -description "This is a test - delete me" -names 'Computer1, Computer2, Computer3'
$filterId = $response.Result
# Add some new names
Add-ComputersByNameToFilter -filterId $filterId -names 'Comp4\r\ncomp5'
# Remove some names
Remove-ComputersByNameToFilter -filterId $filterId -names 'Computer1,Computer2'
# Show current names
Get-ComputersByNameFromFilter -filterId $filterId
# Set the full list of names (overwrite)
Set-ComputersByNameToFilter -filterId $filterId -names 'New1, NewABC'
# Show current names
Get-ComputersByNameFromFilter -filterId $filterId
# Show current names as CSV
Get-ComputersByNameFromFilterAsCsv -filterId $filterId
# Show current names as one name per line
Get-ComputersByNameFromFilterAsLines -filterId $filterId