我在为IIS中嵌套的web应用编写"ConnectAs“域用户帐户时遇到了困难。我的目标环境是带有IIS8的MS Server 2012 R2,但是,我在IIS7.5的Windows 7上看到了同样的问题。
例如,假设我有“默认网站”。下面是"MainApplication“。在这种情况下,我有另一个"SubApplication“的web应用程序。
我在其他类似于下面的网站上尝试了一些建议,取得了部分成功:前两项声明都有效。
Set-WebConfigurationProperty "system.applicationHost/sites/site[@name='Default Web Site']/application[@path='/MainApplication']/virtualDirectory[@path='/']" -name "username" -value "mydomain\user"
Set-WebConfigurationProperty "system.applicationHost/sites/site[@name='Default Web Site']/application[@path='/MainApplication']/virtualDirectory[@path='/']" -name "password" -value "mypassword"对于接下来的两个语句,我似乎无法理解正确的语法:
Set-WebConfigurationProperty "system.applicationHost/sites/site[@name='Default Web Site']/application[@path='/MainApplication/SubApplication']/virtualDirectory[@path='/']" -name "username" -value "mydomain\user"
Set-WebConfigurationProperty "system.applicationHost/sites/site[@name='Default Web Site']/application[@path='/MainApplication/SubApplication']/virtualDirectory[@path='/']" -name "password" -value "mypassword"在一个完美的世界里,我可以做一些类似于下面的事情,使所有的web应用程序都能在同一个域用户帐户下快速运行:
Get-WebApplication | ForEach-Object { $_ | Set-ItemProperty -Name "username" -Value "domain\user" }
Get-WebApplication | ForEach-Object { $_ | Set-ItemProperty -Name "password" -Value "passwordValue" } 或者类似的东西:
Get-WebApplication | ForEach-Object { $_.ChildElements | Select-Object -First 1 | Get-Member -Name "Attributes" | Set-Member -Name "userName" -Value "domain\username" }有一个好的方式来脚本设置所有的网站,应用程序等在一个域用户帐户下运行吗?
发布于 2014-12-05 20:57:49
我最后使用的解决方案是使用xpath来获取每个站点、app &虚拟目录的完整路径。我发现每个类型都需要独立地迭代。下面是我为解决这个问题而创建的函数。
function Set-IIS-ConnectAsUser($username, $password)
{
$dir = Get-Location
cd IIS:\Sites
# update all the web sites to run under the context of the specified user
$webSites = Get-Website
ForEach($webSite in $webSites)
{
$siteName = ($webSite | Select -Property "Name").name
$fullPath = "system.applicationHost/sites/site[@name='$siteName']/application[@path='/']/virtualDirectory[@path='/']"
Set-WebConfigurationProperty $fullPath -Name "username" -Value $username
Set-WebConfigurationProperty $fullPath -Name "password" -Value $password
}
# update all the web applications to run under the context of the specified user
$apps = Get-WebApplication
ForEach($app in $apps)
{
$xpath = ($app | Select -Property "ItemXPath").ItemXPath
$fullPath = "$xpath/virtualDirectory[@path='/']"
$fullPath = $fullPath.Substring(1)
Set-WebConfigurationProperty $fullPath -Name "username" -Value $username
Set-WebConfigurationProperty $fullPath -Name "password" -Value $password
}
# update all the virtual directories to run under the context of the specified user
$virtualDirs = Get-WebVirtualDirectory
ForEach($vdir in $virtualDirs)
{
$xpath = ($vdir | Select -Property "ItemXPath").ItemXPath
$fullPath = $xpath.Substring(1)
Set-WebConfigurationProperty $fullPath -Name "username" -Value $username
Set-WebConfigurationProperty $fullPath -Name "password" -Value $password
}
cd $dir
}发布于 2014-08-09 06:13:20
尝尝这个。用你的名字改变父母和孩子的名字。
Set-WebConfiguration "/system.applicationHost/sites/site[@name='Default Web Site']/application[@path='/parent/child']/virtualdirectory[@path='/']" -Value @{userName='andy';password='password'}发布于 2022-03-11 19:58:41
试试下面的脚本
$deepestPath = "MACHINE/WEBROOT/APPHOST"
$sectionPath = "system.applicationHost/sites/site/application/virtualDirectory"
$appPhysicalPath = "D:\Inetpub\wwwroot\yourApp"
$userName = "domain\serviceaccount"
$password = "#######"
$fullPath=$sectionPath+"[@physicalPath='$appPhysicalPath']"
Set-WebConfigurationProperty -PSPath $deepestPath -Filter $fullPath -Name "userName" -Value $userName
Set-WebConfigurationProperty -PSPath $deepestPath -Filter $fullPath -Name "password" -Value $passwordhttps://stackoverflow.com/questions/25215354
复制相似问题