验证IIS设置的Powershell脚本

3

是否可以使用PowerShell脚本获取IIS设置?

我想使用脚本获取/检查以下信息:

  1. 检查Windows身份验证提供程序是否正确列出(Negotiate,NTLM)
  2. 检查Windows身份验证是否已启用
  3. Windows身份验证高级设置->启用内核模式是否开启
2个回答

6

是的,使用PowerShell很容易实现。网上有很多示例和例子。

查看Windows PowerShell中的(IIS)管理Cmdlets,特别是Get-WebConfigurationGet-WebConfigurationProperty

要获取有关Windows身份验证高级设置的信息,请使用:

$windowsAuthFilter = "/system.WebServer/security/authentication/windowsAuthentication"
$winKernel = (Get-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Default Web Site' -filter "$windowsAuthFilter" -name "useKernelMode").Value
$winKernel 
$winProviders = Get-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location 'Default Web Site' -filter "$windowsAuthFilter/providers" -name "." 
$winProviders.Collection | Format-Table value

尝试过以下代码:Import-Module WebAdministration cd IIS: IIS:\>Get-WebConfiguration -Filter "System.WebServer/Security/Authentication/* /*" -Recurse | where {$_.enabled -eq $True} | Format-List但是出现以下错误: IIS:>Get-WebConfiguration : 无法将'IIS:>Get-WebConfiguration'识别为cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请验证路径是否正确,然后重试。 - Joseph
运行 Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerManagementTools 命令来安装IIS cmdlets,如果你使用的是旧版本的Windows,则可以通过GUI安装它们。 - Peter Hahndorf
以下代码可以正常运行,但输出中没有显示IIS的Windows身份验证是否已启用: Get-WebConfiguration system.webServer/security/authentication/windowsAuthentication/* 'IIS:\sites\Default Web Site' -Recurse | format-list - Joseph

1

以下是有关匿名和Windows身份验证的阅读答案:

$anonAuthFilter =    "/system.WebServer/security/authentication/AnonymousAuthentication"
$windowsAuthFilter = "/system.WebServer/security/authentication/windowsAuthentication"

$value = 'false'
$AppName = "test"

$anonAuth = Get-WebConfigurationProperty -filter $anonAuthFilter -name Enabled -location $AppName
Write-Host  $anonAuth.Value


$winAuth = Get-WebConfigurationProperty -filter $windowsAuthFilter -name Enabled -location $AppName
Write-Host  $winAuth.Value

@Peter Hahndorf 仍然没有找到任何线索

检查Windows身份验证高级设置->启用内核模式并

检查已启用的提供程序,如NTLM和Negotiate


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接