如何使用Powershell更改IIS默认文档顺序?

我如何确保default.aspx是我的IIS网站的第一个默认文档?

我努力了:

Add-WebConfiguration //defaultDocument/files "IIS:\sites\Default Web Site\MyWebSite" -atIndex 0 -Value @{value="Default.aspx"} 

但如果default.aspx已经在列表中抱怨

 Add-WebConfiguration : Filename: Error: Cannot add duplicate collection entry of type 'add' with unique key attribute 'value' set to 'Default.aspx' 

如果有必要,我如何添加它并将它移动到列表顶部?

诀窍是删除“default.aspx”,如果它已经在列表中的任何地方:

 $filter = "system.webserver/defaultdocument/files" $site = "IIS:\sites\Default Web Site\MyWebSite" $file = "default.aspx" if ((Get-WebConfiguration $filter/* "$site" | where {$_.value -eq $file}).length -eq 1) { Remove-WebconfigurationProperty $filter "$site" -name collection -AtElement @{value=$file} } Add-WebConfiguration $filter "$site" -atIndex 0 -Value @{value=$file} 

我们首先检查default.aspx是否存在,如果find,将其删除,然后将其添加回顶部,就像你已经做的一样。