请考虑以下here-string,我试图使用模板进行Nagios定义.
$blankDefinition = @"
define host{
use windows-server ; Inherit default values from a template
host_name {0} ; The name we're giving to this host
alias {0} ; A longer name associated with the host
address {1} ; IP address of the host
}
"@
Run Code Online (Sandbox Code Playgroud)
我有一个脚本可以确定哪些服务器不在nagois中.因为它循环我试图让它为我吐出一个定义,以便我可以复制并粘贴到我的Nagios配置中.
$comparison | %{
$blankDefinition -f $($_.serverName),$($_.ipAddress)
}
Run Code Online (Sandbox Code Playgroud)
哪个让我知道以下错误:
Error formatting a string: Input string was not in a correct format..
Run Code Online (Sandbox Code Playgroud)
像这样的东西工作得很好
@"
Testing
One
{0}
Three
"@ -f "Twelve"
Run Code Online (Sandbox Code Playgroud)
所以我发现它是因为其他花括号.有没有一种方法可以使用-f格式化我的字符串,同时保留括号?或者我只能使用变量替换?