Powershell 禁用匿名 FTP 并启用身份验证

Powershell Disable Anonymous FTP and Enable Authentication

尝试在 PowerShell 中做一些相当简单的事情。在默认 ftp 站点上禁用匿名 FTP 并像这样启用基本身份验证:FTP Authentication.

这是我正在尝试的:

c:\windows\system32\inetsrv\appcmd unlock config /section:anonymousAuthentication
c:\windows\system32\inetsrv\appcmd unlock config /section:basicAuthentication
Set-WebConfigurationProperty -filter /system.webServer/security/authentication/anonymousAuthentication -name Enabled -value false -PSPath 'IIS:\sites\Default FTP Site\'
Set-WebConfigurationProperty -filter /system.webServer/security/authentication/basicAuthentication -name Enabled -value true -PSPath 'IIS:\sites\Default FTP Site\'

这成功了:

Unlocked section "system.webServer/security/authentication/anonymousAuthentication" at configuration path "MACHINE/WEBROOT/APPHOST".
Unlocked section "system.webServer/security/authentication/basicAuthentication" at configuration path "MACHINE/WEBROOT/APPHOST".

但是对实际的IIS配置完全没有影响。我错过了什么?

请试试这个命令行。它将禁用匿名身份验证并启用基本身份验证。请记住以管理员身份 运行 powershell。

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/site[@name='Default FTP Site']/ftpServer/security/authentication/anonymousAuthentication" -name "enabled" -value "False"
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/site[@name='Default FTP Site']/ftpServer/security/authentication/basicAuthentication" -name "enabled" -value "True"