从Windows批处理文件调用powershell cmdlet

前端之家收集整理的这篇文章主要介绍了从Windows批处理文件调用powershell cmdlet前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
好的,这么简单,只是不适合我。我得到一个接受一个参数的cmdlet。我试图在Windows批处理文件调用一个cmdlet。批处理文件包含: @H_403_1@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文件再也没有做任何特别的事情:@H_301_4@ @H_403_1@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文件。@H_301_4@

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

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

谢谢@H_301_4@

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

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

猜你在找的Windows相关文章