I am trying to configure Windows Server 2012 SMTP server using PowerShell.
I plumbed for using the IISSmtpServerSettings CimObject.
I get the object, apply my change (allow localhost to relay sender list) and the script exits without error.
However, now I can't start the SMTP server.
After close inspection of the Cim object before and after my change, it turns out that my SecureBindings setting is also getting changed.
From this: SecureBindings : {SecureBinding (IP = "", Port)}
To this: SecureBindings : {SecureBinding (IP = "", Port = "")}
I tried to set my SecureBindings setting but i get an error "The adapter cannot set the value of property "SecureBindings"
So, my question is, how can I either
- Stop my script from affecting SecureBindings in the first place
- Set SecureBindings to a value which doesn't cause SMTP server to fail startup
My script looks like this:
$ErrorActionPreference = "Stop"
$error.Clear()
# Get Cim object
$smtpInstance = Get-CimInstance -Namespace root/MicrosoftIISv2 -ClassName IIsSmtpServerSetting -Filter "Name = 'SmtpSvc/1'"
# Set relay IP of 127.0.0.1
$relayIPs = @( 24, 0, 0, 128, 32, 0, 0, 128, 60, 0, 0, 128, 68, 0, 0, 128, 1, 0, 0, 0, 76, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 76, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 127, 0, 0, 1 )
# Set relay IP list
$smtpInstance.RelayIpList = $relayIPs
# Save changes
Set-CimInstance -CimInstance $smtpInstance -PassThru
The change you're seeing is a trivial one. The value is being changed from null to an empty string. This is not uncommon for drivers, firmware, or interfaces (wmi, cim, custom applets) to make slight data changes this way.
While I can't point to a specific line of code in your circumstance, I can tell you the most likely way this is occurring. It's not unheard of for a developer to set their code so that null variables are disallowed. To do any kind of work with the object it must be serialized and instantiated. When that's the case the property are assigned their values and a null is transformed into an empty. Believe it or not null and empty are totally different from a programmatic position.
There should be no danger or adverse consequences from this. The failure's your seeing are most likely attributable to something as yet undiscovered. Perhaps the error messages or logs might help? Certainly post them if you have them.
I could not solve the original problem with the CimInstance adding the value "".
However, I did manage to get this to work by switching to an WmiObject: