Q:

PowerShell Modify cmdlet in function

I want to create a Function to run couple of cmdlets.
For Example:
Test-AcctDBConnection -DBConnection $CTXDBString
Test-AdminDBConnection -DBConnection $CTXDBString

All Commands are basicly the same. Just modified after Test-$someParam
I want to create a simple function like this
function CTX-Check {
    Param([string]$Check_Service)

    Write-Host $Check_Service
    try {
        Test-$Check_Service -DBConnection $CTXDBString
    } catch {
        Write-Host -ForegroundColor Yellow $_.Exception.Message
    }    
}

Some Ideas to solve this issue?  If I do the same with Set-$someParam that works fine.

A:

If all of your commands take the same parameters, you can do something like this:
function Test-Citrix {
    [CmdletBinding()]
    param(
        [string]
        $Service,

        [string]
        $DBConnection
    )
    $PSBoundParameters.Remove('Service')

    foreach ($cmd in (Get-Command -Verb Test | ? Source -like Citrix*)) {
        & $cmd.Definition @PSBoundParameters
    }
}

Note: this will only work with functions, not cmdlets to my knowledge.  There are some extra steps involved there.

