Powershell If语句写入txt文件
Powershell If statements write to txt file
好的,我有一个创建图形用户界面的脚本,然后运行几个“if 语句”以输出文本行。它将正确写入控制台,但无法弄清楚如何将其写入 csv 文件。
注意:由于脚本的长度,部分代码未显示。在适当的地方包括注释。
function Build_GV
{
if ($GVC.checked -eq $true) #GVC is defined in the gui code
{
write-host "GV is present. Version is $gv_ver" #$gv_ver is in the gui portion of the code
}
if($GPC.checked -eq $true) #GPC defined in gui code
{
write-host "GP is present. Version is $gv_ver"
}
如果复选框被选中,控制台上的输出是:
GV存在。版本是 33.2
全科医生在场。版本是 33.2
我希望将这两行写入这样的 csv 文件中:
GV存在。版本是 33.2,
全科医生在场。版本是 33.2,
想通了。
在第一个“if”语句之前添加了 $locations = $(
。将 write-host
更改为 write-output
然后在最后关闭括号。然后在函数结束之前,添加 $locations | out-file -filepath "C:\Testpath\text.txt"
现在工作得很好。
好的,我有一个创建图形用户界面的脚本,然后运行几个“if 语句”以输出文本行。它将正确写入控制台,但无法弄清楚如何将其写入 csv 文件。
注意:由于脚本的长度,部分代码未显示。在适当的地方包括注释。
function Build_GV
{
if ($GVC.checked -eq $true) #GVC is defined in the gui code
{
write-host "GV is present. Version is $gv_ver" #$gv_ver is in the gui portion of the code
}
if($GPC.checked -eq $true) #GPC defined in gui code
{
write-host "GP is present. Version is $gv_ver"
}
如果复选框被选中,控制台上的输出是: GV存在。版本是 33.2 全科医生在场。版本是 33.2
我希望将这两行写入这样的 csv 文件中: GV存在。版本是 33.2, 全科医生在场。版本是 33.2,
想通了。
在第一个“if”语句之前添加了 $locations = $(
。将 write-host
更改为 write-output
然后在最后关闭括号。然后在函数结束之前,添加 $locations | out-file -filepath "C:\Testpath\text.txt"
现在工作得很好。