Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

powershell incorrect syntax

Posted on 2013-02-06
6
Medium Priority
?
1,208 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 2000 total points
ID: 38859168
Did you try the code which I posted?
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Stellar Exchange Toolkit: this 5 in 1 toolkit comes loaded with mega-software tool. Here’s an introduction to tools’ usage and advantages:
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

916 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