我正在为CSV导出值创建一个新对象:
New-Object -TypeName PSObject -Property @{
host_name = ($server.name).ToLower()
address = $IPAddress
host_is_collector = "no"
host-preset = "windows-server"
} | Select-Object host_name,address,host-preset | Export-Csv -Path $nConf_import_host_file
问题是其中一行包含破折号(主机预设)。我只需将其更改为下划线,但我的CSV需要此值为破折号。我也可以在创建它之后对整个csv做一个替换 - 但这看起来很脏。 有没有办法在这里使用破折号?
我的错误信息是:
Missing '=' operator after key in hash literal.
At Z:\Scripts\Testscripts\ScanServers_and_check_nagiosV7.ps1:336 char:16
+ host-preset <<<< = "windows-server"
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : MissingEqualsInHashLiteral
答案 0 :(得分:7)
您只需将host-preset
属性名称视为字符串,将括在引号中:
New-Object -TypeName PSObject -Property @{ "host-preset" = "windows-server" }