Solved

powershell incorrect syntax

Posted on 2013-02-06
6
1,000 Views
Last Modified: 2013-02-06
Hi guys i have applied the same principle to a previous question i had raised but im getting stuck. Ive tried multiple ways but enough is enough. i run the following function and get the error below. Thanks guys

function newrecieveconnector {
      param
      (
      [Parameter(Mandatory=$true,Position=0)]
      [string]
      $newrecieveconnector,
      [Parameter(Mandatory=$true,Position=1)]
      [string]
      $IPAddress,
      [Parameter(Mandatory=$true,Position=2)]
      [string]
      $subnet
      )
add-pssnapin microsoft.exchange.management.powershell.e201
new-ReceiveConnector -Name 'Application Connector $newrecieveconnectorSMTP' -Usage 'Custom' -Bindings $IPAddress -Fqdn '$newrecieveconnectorSMTP.lime.corp.com' -RemoteIPRanges $subnet -Server '$newrecieveconnector'
}


error

New-ReceiveConnector : Cannot bind parameter 'Fqdn'. Cannot convert value "$newrecieveconnectorSMTP.lime.corp.com"
to type "Microsoft.Exchange.Data.Fqdn". Error: ""$newrecieveconnectorSMTP.lime.corp.com" isn't a valid SMTP domain.
"
At C:\it\Install Exchange2.ps1:191 char:119
+ new-ReceiveConnector -Name 'Application Connector $newrecieveconnectorSMTP' -Usage 'Custom' -Bindings $IPAddress -Fqd
n <<<<  '$newrecieveconnectorSMTP.lime.corp.com' -RemoteIPRanges $subnet -Server '$newrecieveconnector'
    + CategoryInfo          : InvalidArgument: (:) [New-ReceiveConnector], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.Exchange.Management.SystemConfigurationTasks.Ne
   wReceiveConnector
0
Comment
Question by:cwstad2
  • 3
  • 2
6 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 38859143
Change single quotes to double quotes, single quotes wont expand the VAR..

For example..

'Application Connector $newrecieveconnectorSMTP'  

to

"Application Connector $newrecieveconnectorSMTP"

'$newrecieveconnector' to "$newrecieveconnector"

function newrecieveconnector {
      param
      (
      [Parameter(Mandatory=$true,Position=0)]
      [string]
      $newrecieveconnector,
      [Parameter(Mandatory=$true,Position=1)]
      [string]
      $IPAddress,
      [Parameter(Mandatory=$true,Position=2)]
      [string]
      $subnet
      )
new-ReceiveConnector -Name "Application Connector $($newrecieveconnector)SMTP" -Usage 'Custom' -Bindings $IPAddress -Fqdn "$($newrecieveconnector)SMTP.lime.corp.com" -RemoteIPRanges $subnet -Server "$newrecieveconnector"
}

Open in new window

0
 
LVL 15

Author Comment

by:cwstad2
ID: 38859163
Hi I tried that previously get this when i add the ""

New-ReceiveConnector : Cannot bind parameter 'Name' to the target. Exception setting "Name": "The property value is inv
alid. The value can't contain leading or trailing whitespace."
At C:\it\Install Exchange2.ps1:191 char:27
+ new-ReceiveConnector -Name <<<<  "Application Connector $newrecieveconnectorSMTP" -Usage 'Custom' -Bindings $IPAddres
s -Fqdn "$newrecieveconnectorSMTP.lime.corp.com" -RemoteIPRanges $subnet -Server "$newrecieveconnector"
    + CategoryInfo          : WriteError: (:) [New-ReceiveConnector], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Exchange.Management.SystemConfigurationTasks.NewReceive
   Connector
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38859168
Did you try the code which I posted?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 15

Author Comment

by:cwstad2
ID: 38859178
perfect thanks for the code, was almost there i think
0
 
LVL 15

Author Closing Comment

by:cwstad2
ID: 38859182
your a star, my head has been hurting with this ;')
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 38859188
Try

function newrecieveconnector {
      param
      (
      [Parameter(Mandatory=$true,Position=0)]
      [string]
      $newrecieveconnector,
      [Parameter(Mandatory=$true,Position=1)]
      [string]
      $IPAddress,
      [Parameter(Mandatory=$true,Position=2)]
      [string]
      $subnet
      )
add-pssnapin microsoft.exchange.management.powershell.e201

$Name = "'Application Connector $newrecieveconnector" + "SMTP"
$fqdn = $newrecieveconnector + "SMTP.lime.corp.com"

new-ReceiveConnector -Name $Name -Usage 'Custom' -Bindings $IPAddress -Fqdn $fqdn -RemoteIPRanges $subnet -Server '$newrecieveconnector'
}

Open in new window

0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
A procedure for exporting installed hotfix details of remote computers using powershell
In this video we show how to create a Shared Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Sha…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now