【发布时间】:2013-11-28 04:22:40
【问题描述】:
我的 powershell 脚本与一个以格式发送不同数量参数的外部程序交互
primary site=Peachtree Street
并用逗号分隔
primary site=Peachtree Street, last logon=13 Nov 2013, sender-ip-10.10.10.10
我一直在互联网上搜索如何将 $args 转换为字符串 - 否则 $args 会删除逗号,我需要逗号
这是我对 $args 的尝试
sender-ip=10.10.10.10,主站点位置=peachtree 街,创建者=jsmith
第一个脚本
write-host $args
$args = $args | Out-String
write-host $args
第一个输出
sender-ip=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
第二个脚本
write-host $args
$args = "'" + $args + "'"
write-host $args
第二个输出
sender-ip=10.10.10.10 primary site location=peachtree street created by=jsmith
'System.Object[] site location=peachtree System.Object[] by=jsmith'
第三个脚本
write-host $args
foreach ($i in $args){
$i = $i | Out-String
}
write-host $args
第三个输出
sender-ip=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
但是如何保留逗号????
请帮忙!!!
【问题讨论】:
标签: powershell args