3

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

  1. Stop my script from affecting SecureBindings in the first place
  2. 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

2 Answers 2

0

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.

0

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:

# Get Wmi object
$smtpInstance = Get-WmiObject -Namespace root\MicrosoftIISv2 -ComputerName localhost -Query "Select * From IisSmtpServerSetting"

# 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
$smtpInstance.Put() | Out-Null
1
  • I'd love to know how you got the start of that relayIPs array, the 24, 0, 0.. bit. I've been banging my head on a wall trying to figure out how to convert an IP address in string format (eg "110.34.25.234") to something RelayIpList can use.
    – jkj2000
    Commented Feb 4, 2016 at 0:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .