通过 Powershell 更改远程计算机上 IIS 网站的物理路径
我目前正在开发一个部署脚本,它将获取我的网站,从 svn 导出它,删除其中的任何测试文件等,缩小 javascript/css,将代码复制到远程 Web 服务器,然后切换将现有站点复制到新目录。
到目前为止,除了切换 IIS 中的物理目录之外,一切都正常。
$IIsServer = Get-WmiObject Site -Namespace "root/WebAdministration" -ComputerName $serverIP -Credential $credentials -Authentication PacketPrivacy
$site = $IIsServer | Where-Object {$_.Name -eq $siteName}
当我查看我拥有的值时,我找不到物理路径属性。
任何建议将不胜感激。
I'm currently working on a deployment script that will take my site, export it from svn, remove any testing files etc in it, minify the javascript/css, copy the code to a remote web server, and then switch the physical path of the existing site to the new directory.
So far I have everything working except for switching the physical directory in IIS.
$IIsServer = Get-WmiObject Site -Namespace "root/WebAdministration" -ComputerName $serverIP -Credential $credentials -Authentication PacketPrivacy
$site = $IIsServer | Where-Object {$_.Name -eq $siteName}
When I look into the values I have I cant find the physical path property.
Any suggestions would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这也有效:(
注意使用反引号来继续行)
This also works:
(Note the use of backticks for line continuations)
root/WebAdministration WMI
提供程序的问题在于它的功能不是很丰富。您可以使用
Microsoft.Web.Administration
托管 API 来代替。如果在服务器本身上运行该脚本将起作用。您会注意到,如果您需要远程执行此操作,有一条注释掉的行可能对您有用:
不幸的是,微软并没有想到提供一种提供凭据的方法。这意味着运行脚本的帐户需要远程服务器上授予的所有正确权限。我现在无法尝试此操作,因为我不在 AD 环境附近。
脚本本身将更新站点根物理路径 (
/
)。有关 IIS7 配置的更多信息,请参阅以下链接:
The problem with the
root/WebAdministration WMI
provider is that it's not very feature rich.What you can do is use the
Microsoft.Web.Administration
managed API instead. This script will work if run on the server itself.You'll notice there's a commented out line which might work for you if you need to do this remotely:
Unfortunately MS didn't think to provide a way to supply credentials. This would mean that the account running the script would need all the right permissions granted on the remote server. I can't try this right now because I'm not near an AD environment.
The script itself will update the site root physical path (
/
).For more info about IIS7's configuration see the following link:
我想以@Kev 的帖子为基础。
您可以本地使用他的方法,但正如他所说,没有真正的方法可以为他的注释掉的远程连接方法提供凭据:
$serverManager = [Microsoft.Web.Administration.ServerManager] ::OpenRemote($serverIP)
要使用凭据远程更改物理路径,请使用以下命令:
I'd like to build on top of @Kev's post.
You can use his method locally, but as he says there's no real way of providing credentials for his commented-out method of remotely connecting:
$serverManager = [Microsoft.Web.Administration.ServerManager]::OpenRemote($serverIP)
To change the physical path remotely, with credentials, use the following: