设置、查看身份验证方式
#导航到某站点下:
cd IIS:\Sites\DemoSite\DemoApp #启用站点test01下的Windows身份验证
Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value true -PSPath IIS:\ -Location test01 #启用站点default web site下应用程序pswa的Windows身份验证
Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value true -PSPath IIS:\ -Location 'default web site/pswa' #禁用站点MySite下的匿名身份验证
Set-WebConfiguration system.webServer/security/authentication/anonymousAuthentication -PSPath IIS:\ -Location MySite -Value @{enabled="False"} #启用Form身份验证
$config = (Get-WebConfiguration system.web/authentication 'IIS:\sites\Default Web Site')
$config.mode = "Forms"
$config | Set-WebConfiguration system.web/authentication #为MySite添加身份NTLM和Negotiate身份验证方式
Add-WebConfiguration -Filter system.webServer/security/authentication/windowsAuthentication/providers -PSPath IIS:\ -Location MySite -Value NTLM
Add-WebConfiguration -Filter system.webServer/security/authentication/windowsAuthentication/providers -PSPath IIS:\ -Location MySite -Value Negotiate #查看已安装的身份验证方式
Get-WebConfiguration -filter /system.webserver/security/authentication -PSPath iis:\ #查看站点test01下的windowsAuthentication身份验证方式
Get-WebConfiguration -filter /system.webServer/security/authentication/windowsAuthentication -pspath iis:\ -Location test01 |select *
#同上(只是路径写法不同)
Get-WebConfiguration -filter /system.webServer/security/authentication/windowsAuthentication 'iis:\sites\test01' |select *
设置站点身份验证方式:
Set-WebConfigurationProperty -Filter system.webServer/security/authentication/anonymousAuthentication `
-PSPath MACHINE/WEBROOT/APPHOST `
-Location 'Default Web Site' `
-Name Enabled `
-Value $true
检查某个站点/应用程序下的身份验证方式是否已启用
方法一:
$siteName = "test01"
$authentications=Get-WebConfiguration -filter "system.webServer/security/authentication/*" -PSPath "IIS:\Sites\$siteName"
$authentications | % {$_ |Select ItemXPath,enabled}
方法二(笨方法):
#定义站点名称
$site = "test01"
Import-Module WebAdministration
#获取所有已安装的身份验证方式
$auths = Get-WebConfiguration -filter /system.webserver/security/authentication -PSPath IIS:\
$authnames = $auths.Sections.name
Foreach ($auth in $authnames)
{
$authall = $auths.ItemXPath + "/" + $auth
#查看站点下每个身份验证是否启用
Get-WebConfiguration -filter $authall -pspath IIS:\ -Location $site|select ItemXPath,Enabled
}
IIS PowerShell 管理命令:http://technet.microsoft.com/en-us/library/ee790599.aspx