我正在编写一个与第三方软件接口的脚本。
他们以以下格式发送字符串:
sender-ip=10.10.10.10, primary site location=peachtree street, created by=jsmith
但是,当脚本执行时
Write-host $args
这是输出
sender-ip=10.10.10.10 primary site location=peachtree street created by=jsmith
如何使用逗号保留原始输入字符串?
编辑:
下面是代码snippit
$args = $args.ToString()
write-host '$args is' $args
foreach ($i in $args){
$line_array+= $i.split(",")
write-host '$line_array is' $line_array
}
foreach ($j in $line_array){
$multi_array += ,@($j.split("="))
}
foreach ($k in $multi_array){
$my_hash.add($k[0],$k[1])
}
$Sender_IP = $my_hash.Get_Item("sender-ip")
当我用
执行代码时script.ps1 sender-ip=10.10.10.10, primary site location=peachtree street, created by=jsmith
我得到了
$args is System.Object[]
$line_array is System.Object[]
$Sender_IP is
答案 0 :(得分:1)
它将其解释为多个参数。你需要引用整个事情,所以它只知道一个论点:
&{Write-Host $args} sender-ip=10.10.10.10, primary site location=peachtree street, created by=jsmith
&{Write-Host $args} 'sender 10.10.10.10, primary site location=peachtree street, created by=jsmith'
sender-ip=10.10.10.10 primary site location=peachtree street created by=jsmith
sender 10.10.10.10, primary site location=peachtree street, created by=jsmith