Iis – How to get a list of default documents in IIS using PowerShell

iispowershellwindows-server-core

I'm managing a Server Core machine and trying to do everything in PowerShell, which is fun. I need a list of the default documents. From other websites, I've found out how to set and remove them, using both xxx-WebConfiguration and xxx-WebConfigurationProperty. I've tried:

Get-WebConfigurationProperty -Filter /system.webServer/defaultDocument -PSPath "IIS:\sites\Default Web Site" -Name files

but it gives:

Collection     : {Microsoft.IIs.PowerShell.Framework.ConfigurationElement, Microsoft.IIs.PowerShell.Framework.Configuration
                 Element, Microsoft.IIs.PowerShell.Framework.ConfigurationElement, Microsoft.IIs.PowerShell.Framework.Confi
                 gurationElement...}
ItemXPath      : /system.webServer/defaultDocument
Attributes     : {}
ChildElements  : {}
ElementTagName : files
Methods        :
Schema         : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema

which doesn't really help.

Best Answer

The actual document names are deeper in the hierarchy. Here's how you can get a list of default docs:

Get-WebConfigurationProperty -Filter /system.webServer/defaultDocument/files/add -PSPath "IIS:\sites\Default Web Site" -Name value | Select value