[英]Reading and running Powershell file from text
Right now, I'm trying to use a Powershell script to read through a text file and execute all of the Powershell scripts mentioned in it, but I can't get any results. 现在,我正在尝试使用Powershell脚本来读取文本文件并执行其中提到的所有Powershell脚本,但是我无法获得任何结果。 I've tried specifying it this way: 我试过这样指定它:
Start-Job -ScriptBlock{powershell.exe -noexit $val} -name $jobnum
and this way: 这样:
Start-Job -ScriptBlock{$val}
( $val
is the value of the line of text) but it doesn't run the script that's written on that line. ( $val
是文本行的值),但它不会运行在该行上编写的脚本。
And I've tried this way: 我已经尝试过这种方式:
Start-Job -FilePath($val) -name $jobnum
But I get this error: 但是我得到这个错误:
Start-Job
: Only PowerShell script files are allowed forFilePath
parameter.Start-Job
:FilePath
参数仅允许使用PowerShell脚本文件。 Specify a file with.ps1
extension. 指定扩展.ps1
的文件。
Even though the value of $val
is a legitimate path to a file with ps1
extension! 即使$val
的值是具有ps1
扩展名的文件的合法路径!
My text lines look like this: C:\\Users\\me\\Desktop\\notepad.ps1
我的文本行如下所示: C:\\Users\\me\\Desktop\\notepad.ps1
How do I get my Powershell script to read in text and run the ps1
scripts that have a path given in the text? 如何使Powershell脚本读入文本并运行在文本中具有路径的ps1
脚本?
Concerning 关于
Start-Job -ScriptBlock {powershell.exe -noexit $val} -name $jobnum
you need to specify -ArgumentList
parameter like this: 您需要指定-ArgumentList
参数,如下所示:
Start-Job -ScriptBlock {param($v) .. your command using $v} -name $jobnum -argumentlist $val
Otherwise the $value
is not known to the job. 否则,作业无法知道$value
。
没关系,问题是因为我在执行-FilePath($ val)而不是-FilePath $ val。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.