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