This should sort it. As an aside, you should probably be using “-eq” instead of
“-match”, if only one connector is supposed to match.
$RecvConns = Get-ReceiveConnector | where {$_.name -match "SMTP Relay
Connector"}
forEach ($recvConn in $recvConns) {
Write-Host "Updating", $recvConn.Identity
$RecvConn.RemoteIPRanges += $HostIPConv
Set-ReceiveConnector –Identity $recvConn.Guid -RemoteIPRanges
$RecvConn.RemoteIPRanges
}
From: [email protected] [mailto:[email protected]] On
Behalf Of Sean Martin
Sent: Thursday, December 4, 2014 3:47 PM
To: [email protected]
Subject: [Exchange] PowerShell Help
Good morning/afternoon,
I need a little assistance with a PS script I'm putting together. Just to let
it be known, scripting is not my strong suit.
I'm putting together a powershell script for Junior admins to quickly and
efficiently add or remove IP addresses to a relay connector we have on our
Exchange servers. The entire script accepts input from the user, does some
connectivity checks, dns checks, etc. but the primary function is to gather the
input and simply run the set-receiveconnector cmdlet with the updated IP list.
When I execute the script from the Exchange Management shell, it works
perfectly. However, I would like the admins to be able to execute the script
quickly and easily, and potentially from a PC that doesn't have the EMS
installed.
Here's the code that works when the script is executed from the EMS:
================================================================
$RecvConns = Get-ReceiveConnector | where {$_.name -match "SMTP Relay
Connector"}
forEach ($recvConn in $recvConns) {
Write-Host "Updating", $recvConn.Identity
$RecvConn.RemoteIPRanges += $HostIPConv
Set-ReceiveConnector $recvConn -RemoteIPRanges $RecvConn.RemoteIPRanges
}
================================================================
However, if I add the logic to import a PSsession so the user can simply
right-click and execute in powershell:
================================================================
$ExchSrvr = "server1","server2","server3" | Where {Test-Connection
-ComputerName $_ -Count 1 -Quiet} | Get-Random
$ExchSess = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
("http://{0}.<domain>/PowerShell<http://%7b0%7d.%3cdomain%3e/PowerShell>" -f
$exchsrvr)
Import-PSSession $ExchSess
================================================================
I receive this error when the script attemps to set-receiveconnector:
Cannot process argument transformation on parameter 'Identity'. Cannot convert
the "<servername>\SMTP Relay Connector" value of type
"Deserialized.Microsoft.Exchan
ge.Data.Directory.SystemConfiguration.ReceiveConnector" to type "Microsoft.Exch
ange.Configuration.Tasks.ReceiveConnectorIdParameter".
+ CategoryInfo : InvalidData: (:) [Set-ReceiveConnector], Paramet
erBindin...mationException
+ FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Receive
Connector
I'm having a hard time tracking this issue down. Please note I removed
references to actual server names and domains. The actual script is in the
proper syntax. Appreciate any help anyone can provide.
- Sean