• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

String Concatenation┬┐ not in right order

Im trying to write a function, which looks quite simple:-
function backupMySQL([String]$dbHost, [String]$dbUsername, [String]$dbPassword, [String]$dbName, [String]$emailFrom, [String]$emailTo, [String]$emailSubject)

    $strCmd = "& 'C:\Utils\Powershell\MySQL\mysqldump.exe' -h $dbHost -u $dbUsername -p$dbPassword $dbName"
    write-host $strCmd

Open in new window

Im calling it as:-
backupMySQL("dbHost", "dbUsername", "dbPassword", "dbName", "emailFrom", "emailTo", "emailSubject")

Open in new window

While should output as:-
& 'C:\Utils\Powershell\MySQL\mysqldump.exe' -h dbHost -u dbUsername -pdbPassword dbName

However instead outputs as:-
& 'C:\Utils\Powershell\MySQL\mysqldump.exe' -h dbHost dbUsername dbPassword dbName emailFrom emailTo emailSubject -u  -p

What seems to be happening is all my variables Im passing through seem to be set as one instead of seperate, then its ignoring the others as null.

Any ideas what Im doing wrong with this please?

Thank you
1 Solution
Rainer JeschorCommented:
your calling code is wrong, instead of putting everything in parathensis and separating by "," you simply have to call it like this (no parathensis and space as parameter separator):
backupMySQL "dbHost" "dbUsername" "dbPassword" "dbName" "emailFrom" "emailTo" "emailSubject"

Open in new window

With your call, all values are treated as the first parameter.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now