相关疑难解决方法(0)

从Windows批处理文件调用powershell cmdlet

好的东西这么简单只是不适合我.我有一个接受单个参数的cmdlet.我试图在Windows批处理文件中调用cmdlet.批处理文件包含:

cd %SystemRoot%\system32\WindowsPowerShell\v1.0
powershell Set-ExecutionPolicy Unrestricted
powershell 'C:\convert-utf8-to-utf16.ps1 C:\test.txt'
powershell Set-ExecutionPolicy Restricted
pause
Run Code Online (Sandbox Code Playgroud)

我的ps1文件再没有做任何特别的事:

function convert-utf8-to-utf16 {   
  $tempfile = "C:\temp.txt"
  set-ExecutionPolicy Unrestricted
  get-content -Path $args[0] -encoding utf8 | out-file $tempfile -encoding Unicode
  set-ExecutionPolicy Restricted
}
Run Code Online (Sandbox Code Playgroud)

当我执行bat文件时,它只是运行完成(没有错误消息),它似乎没有创建temp.txt文件.

我可以在PS命令提示符下运行powershell命令文件,但不能在cmd中运行!

任何人有任何想法可能是错的?

谢谢

powershell batch-file

20
推荐指数
4
解决办法
7万
查看次数

标签 统计

batch-file ×1

powershell ×1