用于创建文件夹、网站并使用 MSDeploy.exe 进行部署的 Powershell 脚本
我想在 Windows 2008 R2 上部署 Web 应用程序。我知道执行各种任务的单独 PowerShell 命令。但我想将其放入一个漂亮的 PowerShell 脚本中。
我只需要语法,您能帮我执行以下操作吗:
测试
C:\Inetpub\MyWebsite
文件夹是否存在,如果不存在,则创建它。在 IIS7 中测试
MyWebsite
是否存在,如果不创建它(我知道如何Import-Module WebAdministration
并调用New-WebSite
)现在是复杂的部分。我从 Visual Studio 2010 准备的包中部署了一个网站。VS 提供了一个
.cmd
文件,我只需在 DOS 提示符下执行它即可。这意味着我必须离开 PS 控制台,打开 DOS 控制台才能运行该 cmd 文件。是否可以从 PowerShell 控制台中运行.cmd
文件?
I would like to deploy a web application on Windows 2008 R2. I know the separate PowerShell commands to do various tasks. But I would like to put this into a nice PowerShell script.
I just need the syntax, can you please help me to do the following actions:
Test if
C:\Inetpub\MyWebsite
folder exists, if not, create it.Test in IIS7 if
MyWebsite
exists, if not create it (I know how toImport-Module WebAdministration
and callNew-WebSite
)Now the complicated part. I deploy a Web site from a package prepared by Visual Studio 2010. VS supplies a
.cmd
file where I just need to execute it from a DOS prompt. This means I have to leave the PS Console, open a DOS Console to run that cmd file. Is it possible to run a.cmd
file from within a PowerShell console ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
回答您的问题:
您可以从 PowerShell 中运行
.cmd
脚本。To answer your questions:
You can run
.cmd
scripts from within PowerShell just fine.我也改变了一点点。使用相同的 Test 语法来测试网站是否存在:
同样为了执行 *.cmd 文件,我从网上提取了一些代码,发现人们使用 &执行外部命令。希望您一切顺利:
非常感谢您的帮助。
I have also changed a little bit. Using the same Test syntax to test if a website exists or not:
Also for executing the *.cmd file, I lift some code from the web and saw that people use & to execute external command. Hope that you are OK:
Thank you very much for your help.
如果需要以管理员身份运行.cmd文件,可以使用以下代码:
If you need to run the .cmd file as administrator, you can use the following code: