好吧,这么简单的事情对我不起作用。我有一个接受单个参数的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
}
当我执行bat文件时,它会运行到完成状态(没有错误消息),并且似乎不会创建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的方法。
关于powershell - 从Windows批处理文件调用Powershell cmdlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/932291/