Function: PowerShell Command Get-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 PowerShell Command Get-Command

Function: commandGetCommand

public commandGetCommand(objPowerShellHost: PowerShellHost, strSessionId: string, strArgumentList: string, strVerb: string, strNoun: string, strPSSnapin: string, intTotalCount: number, blnSyntax: boolean, blnVerbose: boolean, blnDebug: boolean, strErrorAction: string, strErrorVariable: string, strOutVariable: string, strOutBuffer: string): PowerShellRemotePSObject {

    let objPowerShellCommand: PowerShellCommand = this.buildPowerShellCommand("Get-Command");

    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 (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)
    }

    let objPowerShellSession: PowerShellSession = objPowerShellHost.getSession(strSessionId);
    objPowerShellSession.addCommand(objPowerShellCommand);

    let blnInPipeline: boolean = objPowerShellHost.inPipeline(strSessionId);

    if (blnInPipeline === false) {

        let objPowerShellRemotePSObject: PowerShellRemotePSObject = this.invokeCommand(objPowerShellHost, strSessionId);

        return objPowerShellRemotePSObject;
    }
    else if (blnInPipeline === true) {
        return null;
    }
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like