简体   繁体   中英

String parameter handling in a Powershell function

Have just dipped my toes (fingers!) in to PowerShell recently for so Backup Exec and was looking to simplify my script by introducing a function to setup backup jobs, so I have started off with:

function submitJob ($beDef,$beTask,$beTape,$beCMD,$beDup)
{
$beCmdLine="GET-BEBackupDefinition ""$beDef"" "
}

I then call the function with

submitJob "SS03ICT","Wednesday (01)","Tape drive 0002 LTO3","powershell SS03-Media Wednesday",$true

and the result in beCmdLine is

GET-BackupDefinition "SS03ICT Wednesday (01) Tape drive 0002 LTO3 powershell SS03-Media Wednesday True"

I can see all the parameters contain the correct values individually but when I use just the first param ($beDef) it expands to include all the values. I just want to command to command to start as

GET-BackupDefinition "SS03ICT"

Thanks in advance

First of all too many quotes:

function submitJob ($beDef,$beTask,$beTape,$beCMD,$beDup)
{
   $beCmdLine="GET-BEBackupDefinition $beDef"
}

Then, you should call your function with space separated parameters, like this:

submitJob "SS03ICT" "Wednesday (01)" "Tape drive 0002 LTO3" "powershell SS03-Media Wednesday" $true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM