随笔 - 911  文章 - 5  评论 - 94  阅读 - 243万

IIS下的身份验证方式管理

设置、查看身份验证方式

复制代码
 1 #导航到某站点下:
 2 cd IIS:\Sites\DemoSite\DemoApp
 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:\sites\Default 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\test01' |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

posted on   momingliu11  阅读(2460)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示