How to run a PowerShell script within a Windows batch file

前端 未结 10 1964
半阙折子戏
半阙折子戏 2020-11-27 16:22

How do I have a PowerShell script embedded within the same file as a Windows batch script?

I know this kind of thing is possible in other scenarios:

  • Em
10条回答
  •  盖世英雄少女心
    2020-11-27 16:45

    This one only passes the right lines to PowerShell:

    dosps2.cmd:

    @findstr/v "^@f.*&" "%~f0"|powershell -&goto:eof
    Write-Output "Hello World" 
    Write-Output "Hello some@com & again" 
    

    The regular expression excludes the lines starting with @f and including an & and passes everything else to PowerShell.

    C:\tmp>dosps2
    Hello World
    Hello some@com & again
    

提交回复
热议问题