Link to home
Start Free TrialLog in
Avatar of cwstad2
cwstad2Flag for United Kingdom of Great Britain and Northern Ireland

asked on

powershell incorrect syntax

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
Avatar of SubSun
SubSun
Flag of India image

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

Avatar of cwstad2

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cwstad2

ASKER

perfect thanks for the code, was almost there i think
Avatar of cwstad2

ASKER

your a star, my head has been hurting with this ;')
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