Thanks again Michael. After reviewing all of this I think I'm going to take
a step back and review what I was trying to accomplish originally. I
considered this to be the first real scripting effort I forced myself to
undertake without robbing somebody else's code. I got so caught up in
everything I was learning, I think I started adding functionality into the
script that ultimately wasn't really necessary.

Maybe when I'm finished you wouldn't mind critiquing the whole script for
me?

- Sean

On Fri, Dec 5, 2014 at 10:19 AM, Michael B. Smith <[email protected]>
wrote:

>  Hydration. Remote PowerShell (EMS) gives you fully hydrated objects.
> PsSessipns do not. This is the cost of not installing the management tools.
>
> Not a silly question.
>
> Sent from my Windows Phone
>  ------------------------------
> From: Sean Martin <[email protected]>
> Sent: ‎12/‎5/‎2014 1:12 PM
>
> To: [email protected]
> Subject: Re: [Exchange] PowerShell Help
>
>   Interesting. I apologize if this is a stupid question, but in regards
> to the original code I was attempting to use, what is different in the way
> it is processed using the Exchange Management Shell vs. when I create a
> session to an Exchange server from PowerShell?
>
> I was able to use the following code from EMS and do an add or subtract
> just by toggling the operand
>
>
> *$RecvConn.RemoteIPRanges += $HostIPConv Set-ReceiveConnector $recvConn
> -RemoteIPRanges $RecvConn.RemoteIPRanges*
>
> The $HostIPConv variable stores a single IP address.
>
> - Sean
>  On Fri, Dec 5, 2014 at 7:56 AM, Michael B. Smith <[email protected]>
> wrote:
>
>>  You can’t do it that way, for a subtraction. You must use either the
>> Remove() or RemoveAt() methods, on the RemoteIpRanges result.
>>
>>
>>
>> How, precisely, to do it is going to be dependent on the exact format of
>> the $HostIPConv variable.
>>
>>
>>
>> *From:* [email protected] [mailto:
>> [email protected]] *On Behalf Of *Sean Martin
>> *Sent:* Friday, December 5, 2014 2:13 AM
>>
>> *To:* [email protected]
>> *Subject:* Re: [Exchange] PowerShell Help
>>
>>
>>
>> So that works when adding an IP address (thank you!), however, I receive
>> the following when attempting to remove an IP address (using -=):
>>
>>
>>
>> *Method invocation failed because [System.Collections.ArrayList] doesn't
>> contain*
>>
>>
>>
>>
>>
>>
>> *  a method named 'op_Subtraction'. At J:\MIS Technical
>> Support\Distributed\Continuity\Continuity Binders\Scripting \Exchange
>> 2010\SMTPRelay\DoNotExecute\RemoveFromRelayList.ps1:92 char:29 +
>> $RecvConn.RemoteIPRanges -= <<<<  $HostIPConv     + CategoryInfo          :
>> InvalidOperation: (op_Subtraction:String) [], Ru    ntimeException     +
>> FullyQualifiedErrorId : MethodNotFound*
>>
>>
>>
>> - Sean
>>
>>
>>
>> On Thu, Dec 4, 2014 at 2:54 PM, Michael B. Smith <[email protected]>
>> wrote:
>>
>> Hmmmm.
>>
>>
>>
>> Willing to try something else?  Try this…
>>
>>
>>
>> $RecvConns = Get-ReceiveConnector | where {$_.name -eq "SMTP Relay
>> Connector"}
>>
>>
>>
>> forEach ($recvConn in $recvConns) {
>>
>> Write-Host "Updating", $recvConn.Identity
>>
>> $RecvConn.RemoteIPRanges += $HostIPConv
>>
>> $recvConn.Guid.ToString() | Set-ReceiveConnector -RemoteIPRanges
>> $RecvConn.RemoteIPRanges
>>
>> }
>>
>>
>>
>> *From:* [email protected] [mailto:
>> [email protected]] *On Behalf Of *Sean Martin
>> *Sent:* Thursday, December 4, 2014 6:13 PM
>> *To:* [email protected]
>> *Subject:* Re: [Exchange] PowerShell Help
>>
>>
>>
>> Thanks for the tip on the operator, that does make better sense.
>>
>>
>>
>> Unfortunately I'm still encountering a similar issue:
>>
>>
>>
>> *Cannot process argument transformation on parameter 'Identity'. Cannot
>> convert*
>>
>>
>>
>>
>>
>> * the "b1645fd1-31c2-46f0-9df6-36cb7285303b" value of type "System.Guid"
>> to type
>> "Microsoft.Exchange.Configuration.Tasks.ReceiveConnectorIdParameter".     +
>> CategoryInfo          : InvalidData: (:) [Set-ReceiveConnector], Paramet
>> erBindin...mationException     + FullyQualifiedErrorId :
>> ParameterArgumentTransformationError,Set-Receive    Connector*
>>
>>
>>
>> On Thu, Dec 4, 2014 at 1:47 PM, Michael B. Smith <[email protected]>
>> wrote:
>>
>> 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" -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
>>
>>
>>
>>
>>
>>
>>
>>
>

Reply via email to