Launching additional Powershell instance with commands from a text file -
i'm writing powershell script takes in text file parameter. text file looks similar this:
echo "1" echo "2" echo "3"
what want each line executed in new powershell instance. in example above, 3 additional instances created , each of 3 execute 1 line text file. i'm able launch instances, cannot instances treat lines in file commands.
$textfile=$args[0] #file powershell commands foreach($cmdd in get-content $textfile){ cmd /c start powershell -noexit -command {param($cmdd) iex $cmdd} -argumentlist $cmdd }
running code opens instances, prints lot of information, , closes. closes cannot see info is. however, since text file composed of printing numbers 1, 2, , 3, don't think it's working correctly. there way keep windows closing after execution?
if you're launching additional instances of powershell powershell, won't need call cmd. try using start-process
:
$textfile=$args[0] #file powershell commands foreach($cmdd in get-content $textfile){ start-process -filepath powershell -argumentlist "-noexit -command $cmdd" }
this leave newly created instances open have asked.
Comments
Post a Comment