通过Powershell更改远程计算机上IIS网站的物理路径 [英] Changing the physical path of an IIS website on a remote machine via Powershell

查看:171
本文介绍了通过Powershell更改远程计算机上IIS网站的物理路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个部署脚本,它将占用我的网站,从svn导出它,删除其中的任何测试文件等,缩小javascript / css,将代码复制到远程Web服务器,然后切换现有站点到新目录的物理路径。

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.

到目前为止,除了在IIS中切换物理目录外,我还能正常工作。

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.

推荐答案

root / WebAdministration WMI 提供程序的问题在于它的功能不是很丰富。

The problem with the root/WebAdministration WMI provider is that it's not very feature rich.

您可以做的是使用 Microsoft.Web.Administration 托管API。如果在服务器本身上运行,该脚本将起作用。

What you can do is use the Microsoft.Web.Administration managed API instead. This script will work if run on the server itself.

[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")

$siteName = "Default Web Site"
$serverIP = "your ip address"
$newPath = "your new path"

$serverManager = New-Object Microsoft.Web.Administration.ServerManager
## $serverManager = [Microsoft.Web.Administration.ServerManager]::OpenRemote($serverIP)
$site = $serverManager.Sites | where { $_.Name -eq $siteName }
$rootApp = $site.Applications | where { $_.Path -eq "/" }
$rootVdir = $rootApp.VirtualDirectories | where { $_.Path -eq "/" }
$rootVdir.PhysicalPath = $newPath
$serverManager.CommitChanges()

如果您需要远程执行此操作,您会注意到有一条注释掉的行可能对您有用:

You'll notice there's a commented out line which might work for you if you need to do this remotely:

## $serverManager = [Microsoft.Web.Administration.ServerManager]::OpenRemote($serverIP)

不幸的是,MS没有想到提供提供凭证的方法。这意味着运行脚本的帐户将需要在远程服务器上授予的所有正确权限。我现在无法尝试这个,因为我不在AD环境附近。

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 (/).

有关IIS7配置的更多信息,请参阅以下链接:

For more info about IIS7's configuration see the following link:


IIS7配置参考> system.applicationHost

这篇关于通过Powershell更改远程计算机上IIS网站的物理路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆