从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

我的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
  }

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

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

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

谢谢

从Powershell版本2开始,您可以像这样运行Powershell脚本
powershell -ExecutionPolicy RemoteSigned -File "C:\Path\Script.ps1" "Parameter with spaces" Parameter2

现在我只能想出一个办法来处理dragging and dropping files to a Powershell script

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...