简体   繁体   English

Powershell函数中的字符串参数处理

[英]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: 最近刚刚将脚趾(手指!)浸入PowerShell中,以便使用Backup Exec,并希望通过引入用于设置备份作业的功能来简化脚本,因此我开始使用:

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 并且beCmdLine中的结果是

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. 我可以看到所有参数分别包含正确的值,但是当我仅使用第一个参数($ beDef)时,它会扩展为包含所有值。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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