PowerShell 脚本如何在 Windows Server 2012 R2 中将 WebDAV 绑定到 HTTPS:
powershell
# 安装 WebDAV 扩展及 IIS 管理工具
Install-WindowsFeature Web-DAV-Publishing,Web-Mgmt-Console
# 创建 SSL 证书并绑定到 IIS 的默认网站
$thumbprint = (New-SelfSignedCertificate -DnsName "example.com" -CertStoreLocation Cert:\LocalMachine\My).Thumbprint
$binding = Get-WebBinding -Port 443 -Name "Default Web Site"
$binding.AddSslCertificate($thumbprint, "my")
# 创建 WebDAV 应用程序
$appPool = New-WebAppPool -Name "WebDAVAppPool" -ManagedRuntimeVersion v4.0
$app = New-WebApplication -Name "WebDAV" -Site "Default Web Site" -PhysicalPath "C:\inetpub\wwwroot\WebDAV" -ApplicationPool $appPool.Name
# 配置 WebDAV 身份验证方式
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/anonymousAuthentication" -Name enabled -Value False
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/basicAuthentication" -Name enabled -Value True
Set-WebConfigurationProperty -Filter "/system.webServer/security/authentication/windowsAuthentication" -Name enabled -Value False
# 配置 WebDAV 访问权限
Remove-WebConfigurationProperty -Filter "/system.webServer/handlers" -Name "WebDAV" -AtElement @{name='path';value='*'}
Add-WebConfiguration -Filter "/system.webServer/handlers" -Value @{name='WebDAV';path='*';verb='*';modules='WebDAVModule';requireAccess='Read,Write'}
# 配置 WebDAV SSL
Set-WebConfigurationProperty -Filter "/system.webServer/security/access" -Name sslFlags -Value "Ssl,SslNegotiateCert"