从 .bat 文件调用 Power shell 函数

Calling Power shell function from .bat file

当我尝试从 .bat 文件调用下面的 power shell 函数时,它没有执行。这里我的函数需要三个参数。我尝试了下面来自 bat file.both 的脚本,但它们没有用。我哪里做错了?

powershell ".\Deploy.ps1 Install-Application -msi '.\test-1.0.1.msi'
 -InstallPath '.\InstallPath'
 -Environment 'Local'"

powershell NoProfile -ExecutionPolicy Bypass -Command  ".\Deploy.ps1 Install-Application -msi '.\test-1.0.1.msi'
 -InstallPath '.\InstallPath'
 -Environment 'Local'"


function Install-Application
{
 param(
  [Parameter(Position=0,Mandatory=$true,HelpMessage="Msi file should be existing")]
  [ValidateScript({Test-Path $_})]
  [Alias("msi")]
  [string]$File,

  [Parameter(Position=1,HelpMessage="Path wherein the resource file will be installed")]
  [Alias("path")]
  [string]$InstallPath,

  [Parameter(Position=2,Mandatory=$true,HelpMessage="Only valid parameters are Local,Dev,Test and Prod")]
  [Alias("env")]
  [ValidateSet("Local","Dev","Prod","Test")]
  [string]$Environment,

  )

不要将它包装在一个函数中,在你的 bat 中只需使用:

powershell.exe -File "c:\pathtoyourfile.ps1" -msi .\test-1.0.1.msi -installpath .\InstallPath -environment Local