We sometimes experience an exception while setting properties on an IIS Website.
In this particular instance the line of code leading to the error was
Set-WebConfigurationProperty -filter "/system.webServer/security/authentication/$($Type)Authentication" -name Enabled -value $valueText -PSPath "IIS:\" -Location $ApplicationName
$Type is "Windows" and $valueText is "False"
The resulting Exception message (partially german, english details below the free-text part):
Set-WebConfigurationProperty : Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
In C:\\[REDACTED]\\Modules\\IIS-Application-Configuration.psm1:83 Zeichen:5
+ Set-WebConfigurationProperty -filter "/system.webServer/security/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) \[Set-WebConfigurationProperty\], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.IIs.PowerShell.Provider.SetConfigurationProperty
Command\
Unfortunately the error is not reproducible, so we have no way of testing any sort of solution, or even test any ideas we have to avoid this. Did anyone ever come across this, or could explain this behavior. Maybe even provide a way to provoke the error, so we can handle the case appropriately and test the fix?
What we tried: We just tried to run it again, and the error was gone. In other instance we tried to deactivate the iis-site before re-executing. But since it was not really reproducible, we were not sure if it was actually solving the problem (the iis-site should be disabled in the script before the execution of this very line anyways).
The usual web-search methods do not seem to yield much help.
Get-WebConfigurationProperty -Filter "/system.webServer/security/authentication/$($Type)Authentication" -Name "enabled" -PSPath "IIS:\" | Out-Nullwas added right before the problematic line. still would feel glad to hear why this is required