I have the list of commands to be invoke in my PC to a server
- Start the cmd.exe as Administrator
- Logon to PPP database with dbmcli.exe
- Run the backup history command to show the last backup
Invoke-Command -Session $session -ScriptBlock {echo "backup_history_list -l DAT -c START,STOP,LABEL,ACTION,RC -Inverted" | Start-Process cmd -Verb runAs | C:\sapdb\clients\DatabaseStudio\pgm\dbmcli.exe -d PPP -n localhost -u "CONTROL,Testing123"}
Does not work.
Error:
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
CategoryInfo : InvalidArgument: (backup_history_...ON,RC -Inverted:PSObject) [Start-Process], ParameterBindingException
FullyQualifiedErrorId : InputObjectNotBound,Microsoft.PowerShell.Commands.StartProcessCommand
PSComputerName : localhost
CodePudding user response:
To use multiple commands in one line use Semicolon (;) after each complete command. Your command will be like this:
Invoke-Command -Session $session -ScriptBlock {echo "backup_history_list -l DAT -c START,STOP,LABEL,ACTION,RC -Inverted" ; Start-Process cmd -Verb runAs | C:\sapdb\clients\DatabaseStudio\pgm\dbmcli.exe -d PPP -n localhost -u "CONTROL,Testing123"}
Here I am shortly describing some of the Operator of Powershell:
Semicolon (;) Operator: It allows you to execute many instructions in first command success or failure.
command1 ; command2 ; command3 [; command4 ...]
OR (||) Operator: Only the command after || will run if the command before || failed to execute.
command1 || command2 || command3 [|| command4 ...]
AND (&&) Operator:If anyone left of an operator fails then all other commands located right of the operator won't be executed.
command1 && command2 && command3 [&& command4 ...]
Pipeline (|) Operator:
This | is called pipeline operator. If you want to use the output of one command as the input of another command then you can use the pipe (|) operator.
command1 | command2 | command3
