使用所有参数从批处理文件调用PowerShell脚本 [英] Call PowerShell Script From Batch File With All Parameters

查看:171
本文介绍了使用所有参数从批处理文件调用PowerShell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题

This question and this blog post address how to pass particular parameters into a PowerShell script from a batch file.

如何将所有参数传递到PowerShell脚本中?基本上,我想使用所有参数,以便批处理文件透明地传递所有参数.

How can one pass all parameters into the PowerShell script? Basically I want to splat all the parameters so that the batch file passes all arguments through transparently.

编辑以获取更多上下文:

我当前正在使用这样的一行:

I'm currently using a line like:

PowerShell.exe -Command "& '%~dpn0.ps1' '%1' '%2'"

这可行,但是会在文件之间创建冗余,因此,如果我更新PowerShell脚本以采用不同的参数,则也必须更新批处理脚本.好的,如果我可以做类似的事情:

This works, but creates a redundancy between the files such that, if I update the PowerShell script to take different arguments, I have to update the batch script as well. What would be nice is if I could do something like:

PowerShell.exe -Command "& '%~dpn0.ps1' '%*'"

推荐答案

尝试以下操作:

powershell -File "%~dpn0.ps1" %*

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆