IIS7遥控管理通过c#
-
14-11-2019 - |
题
我已经找到Microsoft.Web.Administration.dll 和类的服务器管理器,试图控制我们的Windows服务器2008年IIS7的实例。
我已经启用远程管理和可以通过连接IIS远程管理工具,但是当我试图和使用下面我不能连接:
ServerManager.OpenRemote(serverName);
这类不允许我指定一个用户名和密码远程IIS7服务器,作为IIS远程管理工具。
这是所有被称为通过我们的生成过程中使用NAnt.
怎么其他人控制他们的远程IIS7服务器的一部分,他们的CI设置?
解决方案 3
我在最后写了一个wcf服务,在远程计算机上作为服务运行。该服务在具有管理员权限的本地帐户下运行,以便可以更改该计算机上的本地IIS实例。
从我的脚本中,我有一系列与WCF服务通信的自定义任务,并根据需要更改IIS设置。
因为这是一个内部开发的环境,我不是太关心的安全性,我允许的IIS的实际改变非常基本。
其他提示
您需要在域用户(Active Directory用户)下运行应用程序,该应用程序具有更改配置文件的右权限。
Windows身份验证将完成其余的。
作为Oded说,你需要的活动目录,以便能够打开一个连接以远程服务器的使用 ServerManager
.
假设你已经管理员RDP的接入服务器还有一个选择是使用处和用文件夹管理控制台服务器(最with advanced2.0配有最新版本的处)在建立脚本:
到迅速配置处于两个机,不在域:
客户:
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"}'
现在有一些警告。处将打一个洞,在Windows防火墙对于港口5985和5986听者(如果运行Windows2003年,它会使用港口的80 443).这可能不是自己的喜好而且你最好跟你的网络管理员有关如何安全。
一旦你已经处置你会需要的用户帐户配置的远程服务器上是一个成员的管理人员小组。一旦完成,然后你可以试验。在建立服务器:
# the following line will prompt for a username and password, enter the name of the account
# you just configured on the IIS box
$cred = Get-Credential
# next test the connection
Test-WSMan -ComputerName <server_name_or_ip> -Authentication default `
-Credential $cred
如果所有这些都是好的,你应该看下列答复:
wsmid : http://schemas.dmtf.org/wbem/wsman/identity/1/wsmanidentity.x sd ProtocolVersion : http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd ProductVendor : Microsoft Corporation ProductVersion : OS: 6.1.7600 SP: 0.0 Stack: 2.0
接下来的事情是连接到一个公用文件夹管理控制台服务器会议:
Enter-PSSession <server_name_or_ip> -Authentication default -Credential $cred
如果这是成功的,你应该有一个PowerShell提示在远程机器。
使用公用文件夹管理控制台服务器然后你可以载WebAdministration提供PowerShell和操作的许多方面IIS你的心内容:
连接到的遥远的服务器你需要提供一个 PSCredential
对象。如上所述,你将提供这种使用:
$cred = Get-Credential
然而,这总是需要一些相互作用键盘提供一个用户名和密码。很明显这是没有良好的自动化的CI。
但是你可以储存的密码文件。要做到这一运行的下一次(或当的密码变化):
read-host -assecurestring | convertfrom-securestring | out-file C:\securestring.txt
然后当你需要为你 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
等等。
上述大多数应该谨慎从事,如果这个机器是互联网所面临的唯一方法访问是通过互联网。如果是这种情况考虑限制的处口VPN只。