Function: Build a PowerShell Command

by Simon Sparks · 23 September 2026

To use this function add it to the class library file named OrchestratorService.ts

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: OrchestratorService.ts

Description: Orchestrator Function to Build a PowerShell Command

Function: buildPowerShellCommand

public buildPowerShellCommand(strCommand: string, strName?: string, strVerb?: string, strNoun?: string, strArgumentList?: string, strInputObject?: string, strPSSnapin?: string, intTotalCount?: number, strErrorAction?: string, strErrorVariable?: string, strOutVariable?: string, strOutBuffer?: string, blnSyntax: boolean = false, blnPassThru: boolean = false, blnVerbose: boolean = false, blnDebug: boolean = false): PowerShellCommand {

    let objPowerShellCommand: PowerShellCommand = new PowerShellCommand(strCommand);

    if (strName) {
        objPowerShellCommand.addParameter('Name', strName);
    }
    if (strInputObject) {
        objPowerShellCommand.addParameter('InputObject', strInputObject);
    }
    if (strArgumentList) {
        objPowerShellCommand.addParameter('ArgumentList', strArgumentList)
    }
    if (strVerb) {
        objPowerShellCommand.addParameter('Verb', strVerb)
    }
    if (strNoun) {
        objPowerShellCommand.addParameter('Noun', strNoun)
    }
    if (strPSSnapin) {
        objPowerShellCommand.addParameter('PSSnapin', strPSSnapin)
    }
    if (intTotalCount) {
        objPowerShellCommand.addParameter('TotalCount', intTotalCount)
    }
    if (blnSyntax && blnSyntax == true) {
        objPowerShellCommand.addParameter('Syntax', '')
    }
    if (blnPassThru && blnPassThru == true) {
        objPowerShellCommand.addParameter('PassThru', '')
    }
    if (blnVerbose && blnVerbose == true) {
        objPowerShellCommand.addParameter('Verbose', '')
    }
    if (blnDebug && blnDebug == true) {
        objPowerShellCommand.addParameter('Debug', '')
    }
    if (strErrorAction) {
        objPowerShellCommand.addParameter('ErrorAction', strErrorAction)
    }
    if (strErrorVariable) {
        objPowerShellCommand.addParameter('ErrorVariable', strErrorVariable)
    }
    if (strOutVariable) {
        objPowerShellCommand.addParameter('OutVariable', strOutVariable)
    }
    if (strOutBuffer) {
        objPowerShellCommand.addParameter('OutBuffer', strOutBuffer)
    }

    return objPowerShellCommand;
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like