0

I have a batch file to execute the PowerShell script:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -command .\MyPowerShell.ps1
echo message1
echo message2

The batch can run the PowerShell with no problem but the CMD prompt displays the output of the PowerShell script. Is that possible to hide the output of the PowerShell script in the CMD prompt? I still need to deliver some messages in the CMD prompt so terminate CMD is not an option. Any help would be appreciated!

4
  • 1
    Not sure I understand your question. There are several ways to suppress output in Powershell, like Out-Null. Commented Apr 10, 2021 at 23:28
  • @Rno Thanks for the reply, I tried to add Out-Null in my command in the end but the command prompt immediately closes and the PS script did not execute. Commented Apr 10, 2021 at 23:40
  • 1
    Modify your ps1 so it doesn't produce any output Commented Apr 11, 2021 at 0:08
  • @SantiagoSquarzon Your suggestion is pretty smart. I will try it as well! Commented Apr 11, 2021 at 3:03

2 Answers 2

1

Powershell has it's own redirection, but seeing as you are running powershell from cmd and simply do not want to see the output, redirect the output to nul

@echo off
"%windir%\System32\WindowsPowerShell\v1.0\powershell.exe"  -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -command .\MyPowerShell.ps1 >nul 2>&1
echo message1
echo message2
Sign up to request clarification or add additional context in comments.

Comments

0
@echo off
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -NoLogo -NonInteractive -NoProfile -ExecutionPolicy Bypass -command .\MyPowerShell.ps1
cls
echo message1
echo message2
pause

I used the command cls to clear the batch script to hide it

1 Comment

The output still appears like 0.5 sec and disappears immediately. That works for my project. Thank you so much!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.