PowerShell / Crescendo

a module for wrapping native applications in a PowerShell function and module
MIT License
399 stars 37 forks source link

OriginalCommandElements Usage Order #146

Closed ghost closed 2 years ago

ghost commented 2 years ago

While using "OriginalCommandElements" the values added to this always occur before any created parameters.

For instance using one of your sample JSON files: HERE

The usage of this command would output to "docker" as: docker image rm id "YourValue"

For some executables the order in which you output the parameters must be defied in a proper order. For instance Android ADB. You must define your device serial number prior to any other parameters.

Take this ADB command to get a directory listing: adb.exe -s SERIAL shell ls If I were to use "shell", "ls" within the "OriginalCommandElements" it would output my command to ADB as: adb.exe shell ls -s SERIAL This command would immediately fail.

It would be nice if the output order were to be configurable in some way. Either adding a new parameter like "OriginalCommandElementsOrder" or perhaps even within the normal parameter section like:

"Parameters": [
    {
        "OriginalName": "-s",
        "Position": 0,
        "Name": "Serial",
        "ParameterType": "string",
        "Mandatory": true,
        "NoGap": false,
        "Description": "Device serial number",
        "ValueFromPipeline": true,
        "ValueFromPipelineByPropertyName": true
    },
    {
        "Position": 1,
        "Name": "OriginalCommandElements"
    }
}

The actual implementation of this would need to be discussed with the internal team to best determine this though.

Gijsreyn commented 2 years ago

Would be nice if this can be added. Currently trying to use the sc.exe to create services remotely, but cannot figure a way out how to add the original \servername in front of the OriginalCommandElements.

Example: "Verb": "New", "Noun": "ScService", "OriginalName": "C:\Windows\System32\sc.exe", "OriginalCommandElements": ["create"], "SupportsShouldProcess": true, "ConfirmImpact": "High", "DefaultParameterSetName": "Default"

In this case, optionally you can also give the \servername in front of sc \servername create, is this possible already to-do?

(Don't ask me why I'm using sc.exe, as there are plenty of alternatives) ;)

jhoneill commented 2 years ago

Isn't this what the parameter flag ApplyToExecutable is for ? Basically the build order seems to be

JamesWTruher commented 2 years ago

@jhoneill has it correct, ApplyToExecutable is used for this very purpose. They are also sorted, so you may put those in whatever order is appropriate by including that information.