设置、查看身份验证方式
1 #导航到某站点下: 2 cd IIS:SitesDemoSiteDemoApp 3 4 #启用站点test01下的Windows身份验证 5 Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value true -PSPath IIS: -Location test01 6 7 #启用站点default web site下应用程序pswa的Windows身份验证 8 Set-WebConfigurationProperty -filter /system.webServer/security/authentication/windowsAuthentication -name enabled -value true -PSPath IIS: -Location 'default web site/pswa' 9 10 #禁用站点MySite下的匿名身份验证 11 Set-WebConfiguration system.webServer/security/authentication/anonymousAuthentication -PSPath IIS: -Location MySite -Value @{enabled="False"} 12 13 #启用Form身份验证 14 $config = (Get-WebConfiguration system.web/authentication 'IIS:sitesDefault Web Site') 15 $config.mode = "Forms" 16 $config | Set-WebConfiguration system.web/authentication 17 18 #为MySite添加身份NTLM和Negotiate身份验证方式 19 Add-WebConfiguration -Filter system.webServer/security/authentication/windowsAuthentication/providers -PSPath IIS: -Location MySite -Value NTLM 20 Add-WebConfiguration -Filter system.webServer/security/authentication/windowsAuthentication/providers -PSPath IIS: -Location MySite -Value Negotiate 21 22 23 #查看已安装的身份验证方式 24 Get-WebConfiguration -filter /system.webserver/security/authentication -PSPath iis: 25 26 #查看站点test01下的windowsAuthentication身份验证方式 27 Get-WebConfiguration -filter /system.webServer/security/authentication/windowsAuthentication -pspath iis: -Location test01 |select * 28 #同上(只是路径写法不同) 29 Get-WebConfiguration -filter /system.webServer/security/authentication/windowsAuthentication 'iis:sites est01' |select *
设置站点身份验证方式:
1 Set-WebConfigurationProperty -Filter system.webServer/security/authentication/anonymousAuthentication ` 2 -PSPath MACHINE/WEBROOT/APPHOST ` 3 -Location 'Default Web Site' ` 4 -Name Enabled ` 5 -Value $true
检查某个站点/应用程序下的身份验证方式是否已启用
方法一:
1 $siteName = "test01" 2 $authentications=Get-WebConfiguration -filter "system.webServer/security/authentication/*" -PSPath "IIS:Sites$siteName" 3 $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