Yan*_*ard 5 iis powershell web-administration
我需要使用powershell自动配置新的IIS服务器,我需要更改Forms身份验证功能(其overrideMode)的功能委派设置.
我基本上想要改变使用此命令时看到的overrideMode:
Get-WebConfiguration -Filter //system.web/authentication -PSPath 'MACHINE/WEBROOT/APPHOST' | fl *
Run Code Online (Sandbox Code Playgroud)
我可以使用Set-WebConfiguration为其他类型的身份验证方法设置它,例如,对于Windows身份验证,我会这样做:
Set-WebConfiguration -Filter //System.webServer/Security/Authentication/windowsAuthentication -PSPath 'MACHINE/WEBROOT/APPHOST' -Metadata overrideMode -Value Allow
Run Code Online (Sandbox Code Playgroud)
但由于某些原因我不能对//system.web/authentication做同样的事情,我不明白为什么.当我尝试时,我收到此错误:
PS H:\> Set-WebConfiguration -Filter //System.web/Authentication -PSPath 'MACHINE/WEBROOT/APPHOST' -Metadata overrideMode -Value Allow
Set-WebConfiguration : Filename: \\?\C:\Windows\system32\inetsrv\config\applicationHost.config
Line number: 974
Error: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default
(overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
At line:1 char:1
+ Set-WebConfiguration -Filter //System.web/Authentication -PSPath 'MAC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-WebConfiguration], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.IIs.PowerShell.Provider.SetConfigurationCommand
Run Code Online (Sandbox Code Playgroud)
我做错了什么,如何更改此值?还有一些其他委派功能似乎也是一样的.
这适用于Windows Server 2016上的IIS 10
编辑:我注意到当我将委派设置更改为仅使用IIS管理器(而不是Powershell)进行读取时,它会通过将该功能添加到applicationHost.config文件中具有overrideMode ="Deny"的位置来"锁定"该功能.完成此操作后,如果我尝试将其更改回允许使用Powershell,则会出现错误.这就是问题.如果我只使用powershell将其设置为Allow或Deny,则不会出现错误,但更改不会反映在IIS管理器中.似乎对于某些委托权限,IIS管理器使用的方法与Powershell更改overrideMode的方法不同,一旦使用UI锁定,您无法使用Powershell解锁它.
小智 0
您可以检查以确保这些 Windows 功能均已从这篇文章中启用,因为这解决了其中一些功能的相同错误:
您是否可以设置文件的属性,使其不是只读的?
# You may need to use the -Credential parameter for this to work on a remote machine
Set-ItemProperty \\?\C:\Windows\system32\inetsrv\config\applicationHost.config -name IsReadOnly -value $false
Run Code Online (Sandbox Code Playgroud)
然后尝试重新运行您的Set-WebConfiguration命令。
您还可以尝试将该配置文件作为 XML 加载到 PowerShell 中,然后修改overrideMode属性并将其保存回 IIS 路径。
[xml]$XmlDoc = Get-Content -Path '\\?\C:\Windows\system32\inetsrv\config\applicationHost.config'
# '//System.Web/Authentication' is the XPath provided above
$AuthNode = $XMLdoc.SelectSingleNode('//System.Web/Authentication')
$AuthNode.overrideMode = "Allow"
$XmlDoc.Save("\\?\C:\Windows\system32\inetsrv\config\applicationHost.config")
Run Code Online (Sandbox Code Playgroud)
我在这台机器上没有 IIS 设置,但假设 XML 中的 XPATH 有效,您应该能够更改该标志,就像假设当您尝试更新该文件时没有任何内容使用该文件一样。
| 归档时间: |
|
| 查看次数: |
346 次 |
| 最近记录: |