从Windows批处理文件调用powershell cmdlet
发布时间:2020-05-22 23:48:38 所属栏目:Windows 来源:互联网
导读:好的,这么简单,只是不适合我。我得到一个接受一个参数的cmdlet。我试图在Windows批处理文件中调用一个cmdlet。批处理文件包含: cd %SystemRoot%system32WindowsPowerShellv1.0powershell Set-ExecutionPolicy Unrestrictedpowershell C:convert-utf8-to-ut
|
好的,这么简单,只是不适合我。我得到一个接受一个参数的cmdlet。我试图在Windows批处理文件中调用一个cmdlet。批处理文件包含: cd %SystemRoot%system32WindowsPowerShellv1.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:PathScript.ps1" "Parameter with spaces" Parameter2 现在我只能想出一个办法来处理dragging and dropping files to a Powershell script。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
