Public/Get-specRequiredTVGroups.ps1

Function Get-specRequiredTVGroups {
    <#
    .SYNOPSIS
        Gets the TeamViewer groups that the device needs to be added to based on its persona.
 
    .DESCRIPTION
        The Get-specRequiredTVGroups function retrieves the required TeamViewer groups for a device based on its persona.
        It queries an Azure table to get the relevant information and returns an array of group names.
 
    .PARAMETER Persona
        Specifies the persona of the device, which is used to determine the required TeamViewer groups.
 
    .PARAMETER TableName
        Specifies the name of the Azure table containing the relevant information.
 
    .PARAMETER StorageAccount
        Specifies the name of the Azure Storage Account.
 
    .PARAMETER SASToken
        Specifies the Shared Access Signature (SAS) token for accessing the Azure Storage Account.
 
    .EXAMPLE
        Get-specRequiredTVGroups -Persona "UKC" -TableName "MyAzureTable" -StorageAccount "MyStorageAccount" -SASToken "MySASToken"
        Retrieves the required TeamViewer groups for a device with persona "UKC" from the specified Azure table and storage account.
 
    .NOTES
        Author : owen.heaume
        Version : 1.0
 
    #>


    # gets the groups that the device needs to be added to in TeamViewer
    [cmdletbinding()]

    param (
        [string]$Persona,
        
        [parameter (mandatory = $true)]
        [string]$TableName,

        [parameter (mandatory = $true)]
        [string]$StorageAccount,

        [parameter (mandatory = $true)]
        [string]$SASToken

    )


    # Get the row data from the Azure table

    $customFilter = "(PartitionKey eq '$persona')"
    
    $params=@{
         tableName      = $TableName
         StorageAccount = $StorageAccount
         CustomFilter   = $customFilter
         SASToken       =  $SASToken
    }
    
    Write-Verbose "Getting data from Azure table [$TableName]"
    $tblResult = Get-SpecAzTableRowUsingSAS @params  

    # If there is no data returned, then it means that there is no matching persona found under RowKey in the Azure table
    if ($null -eq $tblResult -or $tblResult.Length -eq 0) {
        Write-verbose "No matching persona found in the Azure table. This machines persona is [$persona]. Script will now exit."
        return 1
    }

    # we are only interested in data under the 'groups' header
    # so return the names of the groups
    $requiredGroups = $tblResult.groups

    return $requiredGroups

}