2

I am executing powershell script in cmd.

First i write command

C:\Windows\system32>start powershell.exe Set-ExecutionPolicy RemoteSigned

it works successfully

than for running script i write command

C:\Windows\system32>start powershell.exe C:\\Get-NetworkStatistics.ps1

It also works successfully

the problem is when i try to run the function

    C:\Windows\system32>start powershell.exe Get-NetworkStatistics -computername Gbsi1  | Format-Table -autosize

it gives error that "'Format-Table' is not recognized as an internal or external command, operable program or batch file."

here is the screenshot for it. enter image description here

It runs successfully in powershell but no in cmd. Is there any issue with pipe | which i put before Format-Table

1 Answer 1

5

As your it is, the pipe is interpreted by CMD not powershell. Thus, CMD will try to execute a command named Format-Table, which does not exist (outside powershell).

You can escape it using ^:

start powershell.exe Get-NetworkStatistics -computername Gbsi1 ^| Format-Table -autosize

Or by quoting the complete command line

start powershell.exe "Get-NetworkStatistics -computername Gbsi1 | Format-Table -autosize"

Note that your invocation is erroneous anyhow, you need to provide the -Command option to powershell, like so:

start powershell.exe -Command "Get-NetworkStatistics -computername Gbsi1 | Format-Table -autosize"

Finally, do you really want to use start? It will open a new window, that will close immediately after the command is through. You could also use:

powershell.exe -Command "Get-NetworkStatistics -computername Gbsi1 | Format-Table -autosize"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.