加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

从Windows批处理文件调用powershell cmdlet

发布时间:2020-12-13 21:19:10 所属栏目:Windows 来源:网络整理
导读:好的,这么简单,只是不适合我。我得到一个接受一个参数的cmdlet。我试图在Windows批处理文件中调用一个cmdlet。批处理文件包含: cd %SystemRoot%system32WindowsPowerShellv1.0powershell Set-ExecutionPolicy Unrestrictedpowershell 'C:convert-utf8
好的,这么简单,只是不适合我。我得到一个接受一个参数的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。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读