Functions/Find-StringInMSPCompleteTaskInputs.ps1

<#
.SYNOPSIS
    This function returns whether any of the string inputs to the current MSPComplete task contain a
    specified string value.
.DESCRIPTION
    This function returns whether any of the string inputs to the current MSPComplete task contain a
    specified string value.
    It can perform both case-sensitive and case-insensitive matches for the search string.
#>

function Find-StringInMSPCompleteTaskInputs {
    [CmdletBinding(PositionalBinding=$true)]
    [OutputType([Bool])]
    param (
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$searchString,

        [Parameter(Mandatory=$false)]
        [Switch]$caseSensitive
    )

    # Retrieve the BT runbook environment
    $btRunbookEnvironment = Get-BT_RunbookEnvironment

    # Check if this task is running on the local machine
    if ($btRunbookEnvironment.IsRunningOnLocalMachine) {
        return $false
    }

    # Retrieve the MSPComplete input variables
    # Filter out the non-string variables
    # Concatenate all the string values together
    # Search for the string in the combined string
    try {
        if ($caseSensitive) {
            return (((Get-BT_TaskInstance -Ticket $mspc.Ticket -Id $mspc.AutomationInstanceId -Environment $btRunbookEnvironment.Environment).InputVariables `
                | ForEach-Object -Process { Invoke-Expression "`$Global:$($_.TaskDataName)" } `
                | Where-Object { $_ -is [String] }) -join '') -cLike "*$($searchString)*"
        }
        else {
            return (((Get-BT_TaskInstance -Ticket $mspc.Ticket -Id $mspc.AutomationInstanceId -Environment $btRunbookEnvironment.Environment).InputVariables `
                | ForEach-Object -Process { Invoke-Expression "`$Global:$($_.TaskDataName)" } `
                | Where-Object { $_ -is [String] }) -join '') -like "*$($searchString)*"
        }
    }
    catch {
        return $false
    }
}