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. 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.
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. Specify a file with.ps1
extension.
Even though the value of $val
is a legitimate path to a file with ps1
extension!
My text lines look like this: C:\Users\me\Desktop\notepad.ps1
How do I get my Powe开发者_C百科rshell script to read in text and run the ps1
scripts that have a path given in the text?
Concerning
Start-Job -ScriptBlock {powershell.exe -noexit $val} -name $jobnum
you need to specify -ArgumentList
parameter like this:
Start-Job -ScriptBlock {param($v) .. your command using $v} -name $jobnum -argumentlist $val
Otherwise the $value
is not known to the job.
Never mind, the problem was because I was doing -FilePath($val) instead of -FilePath $val.
精彩评论