Iis 7 IIS7通过c进行远程管理#

Iis 7 IIS7通过c进行远程管理#,iis-7,windows-server-2008,nant,remote-administration,Iis 7,Windows Server 2008,Nant,Remote Administration,我一直在研究Microsoft.Web.Administration.dll和ServerManager类,试图控制我们的Windows Server 2008 IIS7实例 我已启用远程管理,可以通过IIS远程管理工具进行连接,但是,当我尝试并使用以下工具时,我无法连接: ServerManager.OpenRemote(serverName); 此类不允许我像IIS远程管理工具那样在远程IIS7服务器上指定用户名和密码 这都是通过我们使用NAnt的构建过程调用的 作为CI设置的一部分,其他

我一直在研究Microsoft.Web.Administration.dll和ServerManager类,试图控制我们的Windows Server 2008 IIS7实例

我已启用远程管理,可以通过IIS远程管理工具进行连接,但是,当我尝试并使用以下工具时,我无法连接:

ServerManager.OpenRemote(serverName);
此类不允许我像IIS远程管理工具那样在远程IIS7服务器上指定用户名和密码

这都是通过我们使用NAnt的构建过程调用的


作为CI设置的一部分,其他人如何控制其远程IIS7服务器?

您需要在具有更改配置文件权限的域用户(Active Directory用户)下运行应用程序


Windows身份验证将完成其余工作。

正如Oded所说,您需要Active Directory才能使用
ServerManager
打开到远程服务器的连接

假设您拥有管理员RDP访问服务器,则另一种选择是在生成脚本中使用WinRM和远程PowerShell(与最新版本的WinRM附带的PowerShell 2.0配合使用效果最佳):

要为不在域中的两台计算机快速配置WinRM:

客户端:

winrm quickconfig (just say yes) winrm set winrm/config/Client/Auth '@{Basic="true"}' :: Only do this next line if not using HTTPS winrm set winrm/config/Client '@{AllowUnencrypted="true"}' winrm set winrm/config/Client '@{TrustedHosts="hostname_or_ip"}' winrm quickconfig (just say yes) winrm set winrm/config/Service/Auth '@{Basic="true"}' :: See: http://support.microsoft.com/kb/2019527 regarding https winrm quickconfig -transport:https :: Only do this if not using HTTPS AND you are happy about sending credentials :: in clear text. winrm set winrm/config/Service '@{AllowUnencrypted="true"}' 然而,这总是需要一些来自键盘的交互来提供用户名和密码。显然,这对自动化CI没有好处

但是,您可以将密码存储在文件中。要执行此操作,请仅运行以下命令一次(或在密码更改时):

然后,当您需要创建
PSCredential
以向远程服务器进行身份验证时:

$username = "deployment_user"
$password = cat C:\securestring.txt | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential `
         -argumentlist $username, $password

$serverNameOrIp = "192.168.1.1"
Enter-PSSession $serverNameOrIp -Authentication default -Credential $cred
上面的脚本来源于以下博客条目,但为了防止文章变黑,我在这里复制了它:

无论如何,一旦连接到远程服务器,您就可以发出进一步的命令,例如:

Import-Module WebAdministration
CD IIS:\Sites
等等


如果这台机器面向互联网,且唯一的访问方式是通过互联网,则应谨慎处理上述大部分内容。如果是这种情况,只考虑将WRRM端口限制为VPN。

< P>我写了一个WCF服务,它在远程机器上作为服务运行。该服务在具有管理员权限的本地帐户下运行,以便可以更改该计算机上的本地IIS实例

从NAnt脚本中,我有一系列自定义任务,这些任务与WCF服务通信,并根据需要更改IIS设置


由于这是一个内部开发环境,我不太关心安全性,允许对IIS进行的实际更改非常基本。

需要哪些权限?我假定对文件夹有写入权限:%systemroot%\System32\inetsrv\Config
Enter-PSSession <server_name_or_ip> -Authentication default -Credential $cred
$cred = Get-Credential
read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt
$username = "deployment_user"
$password = cat C:\securestring.txt | convertto-securestring
$cred = new-object -typename System.Management.Automation.PSCredential `
         -argumentlist $username, $password

$serverNameOrIp = "192.168.1.1"
Enter-PSSession $serverNameOrIp -Authentication default -Credential $cred
Import-Module WebAdministration
CD IIS:\Sites