Using Powershell to set SMTP port on an existing IIS 6 SMTP Server - Windows Server 2012 R2

Background

I have a requirement to restore a snapshot of a server daily into a testing environment, once restored, it is necessary to update numerous bits of configuration to make it a test environment. I have managed to update all of the settings I need with one exception, the Port on which the SMTP server is running.

The server is a Windows 2012 R2 server, all of the websites it hosts are running on IIS8, while the SMTP server is running in IIS6, the compatibility packs, WMI extensions are all installed (although the later via the update script).

The issue is I cannot find a way to update the SMTP inbound port from port 25 via a script.

The rest of my update script is written in Powershell, if possible, I would like to remain in powershell to make the changes.

I have tried using appcmd, but cannot find a relevant setting to update, the same with WMI, I have manually changed the SMTP port to try to locate a field to update but this has so far proved of no luck.

Any help that can be given would be greatly appreciated.

Rob

UPDATE

OK, so I actually managed to solve this myself :)

$Serverbindings = (gwmi -namespace root\microsoftiisv2 -class iissmtpserversetting)
$Bindings = $ServerBindings.ServerBindings
foreach ($Binding in $bindings) {
$Binding.Port = "2525"
} 
$Serverbindings.ServerBindings = $Bindings
$ServerBindings.Put()

In case this is useful to anyone else in the future.

0
задан 9 September 2016 в 13:48
1 ответ

Хорошо, так что мне действительно удалось решить эту проблему самому :)

$Serverbindings = (gwmi -namespace root\microsoftiisv2 -class iissmtpserversetting)
$Bindings = $ServerBindings.ServerBindings
foreach ($Binding in $bindings) {
$Binding.Port = "2525"
} 
$Serverbindings.ServerBindings = $Bindings
$ServerBindings.Put()

На случай, если это пригодится кому-то еще в будущем.

3
ответ дан 4 December 2019 в 12:22

Теги

Похожие вопросы