按顺序运行多个 Powershell 脚本 - 在一个文件夹上 - 将脚本组合成一个主脚本 [英] Run Multiple Powershell Scripts Sequentially - on a Folder - Combine Scripts into a Master Script
问题描述
我有 6 个以上的脚本并且越来越多地在一个文件夹上运行,让它们一个接一个运行的最佳方法是什么.
I have 6+ scripts and growing to run on a folder, what is the best way to have them run one after the other.
我已经看到并尝试过这个线程 - 不幸的是它没有工作.
I have seen and tried this thread - it did not work unfortunately.
在主 .ps 文件中 - 我已经放置了需要按顺序运行的 power shell 脚本的链接
In a master .ps file - I have put links to the power shell scripts that need to be run in order
'C:\Users\WP\Desktop\Scripts\1.ps1'
'C:\Users\WP\Desktop\Scripts\2.ps1'
'C:\Users\WP\Desktop\Scripts\3.ps1'
等
这也不起作用.感谢您的帮助 - 我已经搜索了所有内容,但似乎无法解决此问题.
This did not work either. Your help is appreciated - I have searched all over and can't seem to fix this issue.
修订:我相信我必须等待每个 power shell 脚本完成才能运行下一个脚本 - 因为当我尝试一个接一个地运行 3 个脚本时出现错误 - 没有脚本运行时发生
Revised: I believe I will have to wait for each power shell script to finish before running the next one - as I have had errors when I tried to run 3 scripts one after the other - nothing happened when the scripts were run
决赛 -
感谢大家的帮助 - 为了让事情变得简单,这就是我所做的
I thank you all for your help - to keep things simple this is what I have done
我的文件夹包含以下脚本 - 然后我创建了一个 Master.ps1,其中包含以下代码:
My folder has the scripts below - I have then created a Master.ps1 with the code below inside it:
&"$PSScriptroot\1.ps1"
&"$PSScriptroot\2.ps1"
&"$PSScriptroot\3.ps1"
&"$PSScriptroot\4.ps1"
&"$PSScriptroot\5.ps1"
&"$PSScriptroot\6.ps1"
然后我在包含所有文件的文件夹上运行 Master.ps1 - 到目前为止它完成了工作.
I have then run the Master.ps1 on the folder with all the files - and it does the job so far.
推荐答案
如果不想硬编码路径,可以把Master.ps1做成这样:
If you don't want to hard code the path, you can make Master.ps1 like this:
&"$PSScriptroot\1.ps1"
&"$PSScriptroot\2.ps1"
&"$PSScriptroot\3.ps1"
它会在它所在的同一目录中查找那些脚本.
And it will look for those scripts in the same directory where it is.
这篇关于按顺序运行多个 Powershell 脚本 - 在一个文件夹上 - 将脚本组合成一个主脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!