从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。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- win7下建立超级隐藏账户
- 添加“Microsoft.jQuery.Unobtrusive.Validation”包请求jQ
- 键盘 – 是否值得为不使用Emacs的Windows用户交换Ctrl和Cap
- Windows Server 2012 R2上的随机BSOD
- windows-server-2012-r2 – 当没有用户登录到Windows终端服
- windows – 有没有办法减少Azure部署启动和被调用的角色OnS
- 有没有找到Windows DLL的MD5或其他校验和的地方?
- 将Windows Azure Web角色升级到Server 2008 R2以使用IIS 7.
- wpf – 如何将System.Windows.Media.Color对象序列化到sRGB
- .net – 使用后删除临时文件