【问题标题】:How can I use PowerShell to get the providers information from web.config for all sites in IIS?如何使用 PowerShell 从 web.config 获取 IIS 中所有站点的提供程序信息?
【发布时间】:2021-08-06 16:28:34
【问题描述】:

我需要识别允许跨企业中所有主机进行 NTLM 身份验证的 IIS 站点。 PowerShell 已经安装在每台主机上,因此 PowerShell 似乎是显而易见的解决方案。

我没有在 PowerShell 上花费很多时间,但这是我迄今为止想出的代码。它似乎正确地遍历了我的站点列表,并且我可以获取 providers 元素,但我无法检查 add 元素属性的值。

我还尝试使用“类似问题”功能查看其他问题和答案。

这是代码

$site_list = Get-IISSite
foreach($site in $site_list)
{
    $ConfigSection = Get-IISConfigSection("system.webServer/security/authentication/windowsAuthentication")
    foreach ($attribute in $ConfigSection.Attributes)
    {
        if($attribute.Name -eq "enabled")
        {
            Write-Host $site.Name : $attribute.Name : $attribute.Value
        }

    }
    
    foreach($element in $ConfigSection.ChildElements)
    {
        
        if ($element.ElementTagName -eq "providers")
        {
            Write-Host ChildElements.Count : $element.ChildElements.Count
            $element.Attributes
            $element|fl
            Write-Host Attributes Count : $element.Attributes.Count
            #$elem_attributes = $element.Attributes
            
            foreach ($elem_attr in $elem_attributes)
            {
                Write-Host $elem_attr
            }
        }
    }

}

我的 format-list 输出显示了一个子元素,其 ElementTagName 为 add,属性为 Value。但是,当我显示 Attributes 属性的 Count() 时,它显示为 0。我认为 OOP 术语以及 XML 元素和属性令人困惑,因此我的某些术语可能不正确。任何人都可以提供的任何帮助或指导都会有所帮助。

这是元素格式列表的示例输出。

Attributes      : {value}
ChildElements   : {}
ElementTagName  : add
IsLocallyStored : True
Methods         : 
RawAttributes   : {[value, Negotiate]}
Schema          : Microsoft.Web.Administration.ConfigurationElementSchema

Attributes      : {value}
ChildElements   : {}
ElementTagName  : add
IsLocallyStored : True
Methods         : 
RawAttributes   : {[value, NTLM]}
Schema          : Microsoft.Web.Administration.ConfigurationElementSchema

【问题讨论】:

    标签: powershell iis ntlm


    【解决方案1】:

    我仍在使用旧的 WebAdministration cmdlet:

    Get-WebSite | Foreach-Object {
        Write-Output $_.Name
        Get-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST/$($_.Name)"  -filter "system.webServer/security/authentication/windowsAuthentication/providers/*" -name "." | Format-Table Value
    }
    

    这还将显示从服务器级别继承的提供程序。

    【讨论】:

    • 谢谢彼得,这照顾了我。我能够在几秒钟内使用 SCCM 检查我的所有主机并获得所有不安全的提供程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-27
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多