Você pode usar um código como este:
$site = "Default Web Site"
try
{
Get-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -location "$site" -filter "system.webServer" -name . | Out-Null
Write-Output "All is Well"
}
catch [System.Exception]
{
Write-Output $_
}
A saída pode incluir:
Get-WebConfigurationProperty : Filename: \?\C:\inetpub\wwwroot\web.config
Line number: 7
Error: Configuration file is not well-formed XML
ou
Get-WebConfigurationProperty : Filename: \?\C:\inetpub\wwwroot\web.config
Line number: 5
Error: The configuration section 'foo' cannot be read because it is missing a section declaration