本文介绍了将参数传递给powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从运行对话框运行一个powershell脚本(将用作计划任务),我遇到麻烦传递参数。
I'm trying to run a powershell script from the run dialog (will be used as a scheduled task), and I'm having troubles passing parameters.
该脚本将接受两个参数,名为title和msg。
脚本位于: D:\Tasks Scripts\Powershell\script.ps1
The script will take in two parameters, named title and msg.The script is located in: D:\Tasks Scripts\Powershell\script.ps1
这是我想要做的:
powershell.exe -noexit 'D:\Tasks Scripts\Powershell\script.ps1' -title 'Hello world' -msg 'This is a test message'
但是它在读取参数时失败。
But it fails upon reading the parameters.
运行 .\script.ps1 -title'Hello world'-msg'这是一个测试
Running .\script.ps1 -title 'Hello world' -msg 'This is a test message'
on powershell works fine.
推荐答案
使用 -file code>到您的脚本的路径之前:
Use -file
before the path to your script:
powershell.exe -noexit -file 'D:\Tasks Scripts\Powershell\script.ps1' etc...
这篇关于将参数传递给powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!