好的,有些简单的东西对我来说就是行不通。我有一个接受单个参数的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中不能运行!
有人有任何想法可能出了什么问题吗?