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" -f $exchsrvr)
Import-PSSession $ExchSess
================================================================
I receive this error when the script attemps to set-receiveconnector:
*Cannot process argument transformation on parameter 'Identity'. Cannot
convertthe "<servername>\SMTP Relay Connector" value of type
"Deserialized.Microsoft.Exchange.Data.Directory.SystemConfiguration.ReceiveConnector"
to type
"Microsoft.Exchange.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