Pipeline on OS-COMMAND

Posted by Peterson de Carvalho on 03-May-2017 12:04

I'm trying to run a simple command line (PowerShell) that uses the pipeline once.

But the terminal appears to interpret what follows the pipe as a new command and not as something that will use the previous output.

This is the command line:

ASSIGN command = "powershell.exe Get-ADUser -LDAPFilter '(displayName=John Doe)' -Properties Department | Select Name, Department".

The output is:

'Select' is not recognized as an internal or external command, operable program or batch file.

Is there something that can be done in order to use the pipeline properly within OS-COMMAND?

Thank you all.

Posted by asaynes on 03-May-2017 12:34

Try:

ASSIGN command = "powershell.exe  ~"Get-ADUser -LDAPFilter '(displayName=John Doe)' -Properties Department | Select Name, Department~" ".

Posted by egarcia on 03-May-2017 12:35

Hello,

The message that you are seeing seems to happen because cmd.exe (%ComSpec%) is processing two commands:

1) powershell.exe Get-ADUser -LDAPFilter '(displayName=John Doe)' -Properties Department

2) Select Name, Department

You would need to change your command to be a single command for powershell.exe.

Example:

DEFINE VARIABLE cCommand AS CHARACTER NO-UNDO.

cCommand = 'powershell.exe "Get-ChildItem C:\w* | Select Name"'.

OS-COMMAND VALUE(cCommand).

I hope this helps.

All Replies

Posted by asaynes on 03-May-2017 12:34

Try:

ASSIGN command = "powershell.exe  ~"Get-ADUser -LDAPFilter '(displayName=John Doe)' -Properties Department | Select Name, Department~" ".

Posted by egarcia on 03-May-2017 12:35

Hello,

The message that you are seeing seems to happen because cmd.exe (%ComSpec%) is processing two commands:

1) powershell.exe Get-ADUser -LDAPFilter '(displayName=John Doe)' -Properties Department

2) Select Name, Department

You would need to change your command to be a single command for powershell.exe.

Example:

DEFINE VARIABLE cCommand AS CHARACTER NO-UNDO.

cCommand = 'powershell.exe "Get-ChildItem C:\w* | Select Name"'.

OS-COMMAND VALUE(cCommand).

I hope this helps.

This thread is closed