Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell附加到文件而不是附加字符串_Powershell - Fatal编程技术网

Powershell附加到文件而不是附加字符串

Powershell附加到文件而不是附加字符串,powershell,Powershell,我定义了一个函数将标题附加到输出文件 function appendTitle($filePath, [string]$title){ Add-Content -Path $filePath -Value "+------------------------+" Add-Content -Path $filePath -Value $title Add-Content -Path $filePath -Value "+------------------------+" } 问题是

我定义了一个函数将标题附加到输出文件

function appendTitle($filePath, [string]$title){

Add-Content -Path $filePath -Value "+------------------------+" 
Add-Content -Path $filePath -Value $title 
Add-Content -Path $filePath -Value "+------------------------+" 


}
问题是,如果我这样运行它:

appendTitle($filePath, "Net Accounts")
但在输出文件中,它不包括$title变量,只显示:

+------------------------+

+------------------------+

那么,我想附加的变量到哪里去了呢?

这是因为在括号中运行它,就像这样运行它:

appendTitle $filepath "Net Accounts"

这是因为你在括号内运行它,就像这样运行:

appendTitle $filepath "Net Accounts"

这是因为你在括号内运行它,就像这样运行:

appendTitle $filepath "Net Accounts"

这是因为你在括号内运行它,就像这样运行:

appendTitle $filepath "Net Accounts"

更多信息:函数需要两个参数,一个是
$filepath
参数,它没有键入,因此可以是任何内容,另一个是
$title
参数,它需要是字符串。您传递的是一个参数,它是由两件事组成的数组,第一个是
$filepath
,第二个是“Net Accounts”,根本没有第二个参数。更多信息:函数需要的是两个参数,一个
$filepath
参数,它不是键入的,所以它可以是任何东西,和一个
$title
参数,该参数应为字符串。您传递的是一个参数,它是由两件事组成的数组,第一个是
$filepath
,第二个是“Net Accounts”,根本没有第二个参数。更多信息:函数需要的是两个参数,一个
$filepath
参数,它不是键入的,所以它可以是任何东西,和一个
$title
参数,该参数应为字符串。您传递的是一个参数,它是由两件事组成的数组,第一个是
$filepath
,第二个是“Net Accounts”,根本没有第二个参数。更多信息:函数需要的是两个参数,一个
$filepath
参数,它不是键入的,所以它可以是任何东西,和一个
$title
参数,该参数应为字符串。您传递的是一个参数,它是两件事的数组,第一个是
$filepath
,第二个是“Net Accounts”,根本没有第二个参数。