如何使用powershell在IIS中使用自定义帐户启用匿名身份验证

如何使用powershell在IIS中使用自定义帐户启用匿名身份验证,powershell,iis,Powershell,Iis,我可以通过下面的命令使用powershell启用匿名身份验证 Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -PSPath IIS:\\Sites\\test1 -Name Enabled -Value True 但是我还需要添加带有用户名和密码的自定义帐户(test/test123),同时启用匿名身份验证,而不是默认用户。任何人都可以

我可以通过下面的命令使用powershell启用匿名身份验证

Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -PSPath IIS:\\Sites\\test1 -Name Enabled -Value True

但是我还需要添加带有用户名和密码的自定义帐户(test/test123),同时启用匿名身份验证,而不是默认用户。任何人都可以提供相同的命令吗?

APPCMD.exe是管理IIS 7及以上版本的单一命令行工具

该工具位于:C:\Windows\System32\inetsrv中

您可以在PowerShell中这样使用它:

cd C:\Windows\System32\inetsrv
.\appcmd.exe set config "SiteName" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:"True" /commit:apphost
.\appcmd.exe set config "SiteName" -section:system.webServer/security/authentication/anonymousAuthentication /userName:"IUSR" /commit:apphost
.\appcmd.exe set config "SiteName" -section:system.webServer/security/authentication/anonymousAuthentication /password:"P@ssw0rd" /commit:apphost

命令详细信息。

我不是powershell方面的专家。但是,powershell的每个参数只接受一个参数。如果要在一条语句中传递多个参数,则比执行三条语句更麻烦

或者,您可以将这三条语句写入一个脚本,通过执行一次脚本,您可以启用匿名身份验证并同时设置用户

  • 创建一个txt文件并将其重命名为xxx.ps1。键入以下powershell命令

    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/security/authentication/anonymousAuthentication" -name "enabled" -value "True"
    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/security/authentication/anonymousAuthentication" -name "userName" -value "test"
    Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Default Web Site'  -filter "system.webServer/security/authentication/anonymousAuthentication" -name "password" -value "test123"
    
  • 打开powershell并输入命令

  • &'D:\change.ps1'


    然后它就会工作。

    这是为了启用匿名身份验证自定义用户和密码吗?我已经编辑了我的答案以满足您的需要。谢谢,但是我正在寻找Set-WebConfigurationProperty命令您是否尝试过:Set-WebConfigurationProperty system.webServer/security/authentication/anonymousAuthentication-Name username-value myuser Set-WebConfiguration Property system.webServer/security/authentication/anonymousAuthentication-Name password-value mypassword别忘了添加您的-pspathy正在工作,但不在单个命令中