ITnewbie
ITnewbie

Reputation: 520

Batch file run Powershell and hides the output

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!

Upvotes: 0

Views: 2934

Answers (2)

user7818749
user7818749

Reputation:

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

Upvotes: 1

yeyeyeyeyeyeyeyeyye
yeyeyeyeyeyeyeyeyye

Reputation: 28

@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

Upvotes: 0

Related Questions