How to run a PowerShell script within a Windows batch file

前端 未结 10 1965
半阙折子戏
半阙折子戏 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 17:03

    Without fully understanding your question, my suggestion would be something like:

    @echo off
    set MYSCRIPT="some cool powershell code"
    powershell -c %MYSCRIPT%
    

    or better yet

    @echo off
    set MYSCRIPTPATH=c:\work\bin\powershellscript.ps1
    powershell %MYSCRIPTPATH%
    

提交回复
热议问题