0

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.

1
  • turns out, another part of our company has solved it by getting the same value before setting it. Get-WebConfigurationProperty -Filter "/system.webServer/security/authentication/$($Type)Authentication" -Name "enabled" -PSPath "IIS:\" | Out-Null was added right before the problematic line. still would feel glad to hear why this is required Commented Sep 26, 2023 at 10:43

1 Answer 1

0

This error usually occurs when you try to access or manipulate an object that has not been properly initialized or does not exist.

When you use the Set-WebConfigurationProperty cmdlet to modify a property, the property you are trying to modify must already exist and be accessible. You can check whether the property you want to modify exists in the configuration by using Get-WebConfigurationProperty before Set-WebConfigurationProperty.

If it does not exist, the Get-WebConfigurationProperty command returns null or an empty result. If it exists, running Get-WebConfigurationProperty can help ensure that it is properly initialized and accessible.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.