Advertisement
hackoo

Using Powershell with Foreground Colors in a Batch File

May 18th, 2022 (edited)
560
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @echo off
  2. REM https://www.reddit.com/r/Batch/comments/us3xry/multiple_colors_in_batch/
  3. Title Using Powershell with Foreground Colors in a Batch File
  4. Call :PSColor "You have a " White -NoNewLine & Call :PSColor " Red String " Red
  5. pause
  6. Set Colors=DarkRed Red DarkGreen Green DarkBlue Blue DarkYellow Yellow DarkMagenta Magenta DarkCyan Cyan DarkGray Gray White
  7. @for %%a in (%Colors%) do Call :PSColor "You have a " White -NoNewLine & Call :PSColor " %%a String " %%a
  8. Pause & Exit /B
  9. ::-----------------------------------------------------------------------------------
  10. :PSColor <String> <Color> <-NoNewLine>
  11. If /I [%3] EQU [-NoNewLine] (
  12.     Powershell Write-Host "`0%~1" -ForegroundColor %2 %3
  13. ) Else (
  14.     Powershell Write-Host "`0%~1" -ForegroundColor %2
  15. )
  16. Exit /B
  17. ::-----------------------------------------------------------------------------------
Advertisement
RAW Paste Data Copied
Advertisement