How to pass command-line arguments to a PowerShell ps1 file

前端 未结 7 886
Happy的楠姐
Happy的楠姐 2020-12-12 23:21

For years, I have used the cmd/DOS/Windows shell and passed command-line arguments to batch files. For example, I have a file, zuzu.bat and in it,

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-12 23:47

    Maybe you can wrap the PowerShell invocation in a .bat file like so:

    rem ps.bat
    @echo off
    powershell.exe -command "%*"
    

    If you then placed this file under a folder in your PATH, you could call PowerShell scripts like this:

    ps foo 1 2 3
    

    Quoting can get a little messy, though:

    ps write-host """hello from cmd!""" -foregroundcolor green
    

提交回复
热议问题