Functions/commands.ps1

function Invoke-Commands(
    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [object[]]$commands,
    [string[]]$excludeList) {
    foreach ($command in ($commands | Where-Object {($_.PSObject.Properties.Name -CNotIn $excludeList)})) {
        Invoke-SimpleCommand $command
    }
}

function Invoke-SimpleCommand(
    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [object]$command) {
    if ($property -isnot [string]) {
        $cmdName = $command.PSObject.Properties.Name
        $cmdExec = $command.PSObject.Properties.Value
        Write-Host "Execute command '$cmdName': '$cmdExec'..." -ForegroundColor Cyan
    }
    else {
        $cmdExec = $command
        Write-Host "Execute command '$cmdExec'..." -ForegroundColor Cyan
    }
    Invoke-Expression $cmdExec
}

function Install-ConfigSection(
    [Parameter(Mandatory = $true)]
    [object]$options,
    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [string]$sectionName,
    [Parameter(Mandatory = $true)]
    [ValidateNotNullOrEmpty()]
    [string]$PropertyCommandListName = "commands"
) {
    if (!$options -or !$options.commandName -or $options.isDisabled) {
        Write-Warning "${sectionName}: 'options' or 'commandName' not found or is currently 'disabled'. Skipped"
        return
    }

    if ($options.$PropertyCommandListName -and $options.$PropertyCommandListName.Count -gt 0) {
        $command = "$($options.commandName) $($options.prefix) "
        foreach ($package in $options.$PropertyCommandListName) {
            $command += "${package} "
        }
        Write-Warning "trying to invoke command: ${command}"
        Invoke-Expression $command
    }
    else {
        Write-Host "${sectionName}: ${PropertyCommandListName} not found!"
    }
}