Powershell - 将字符串输出为CSV和格式 [英] Powershell - Output string to CSV and format

查看:641
本文介绍了Powershell - 将字符串输出为CSV和格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面给出一个简单的例子。有人知道我必须做的输出字符串到两列。我的搜索没有返回太多的格式输出到CSV格式的方式。请指点我的方向正确!

I've given a simple example below. Does anyone know what I have to do to output the string into two columns. My searching has not returned much in the way of formatting outputs into CSV. Please point me in the right direction! Thanks!!!

$LogFile = c:\somefile.csv
"Hello World" | Out-File $LogFile


推荐答案

问题,在您尝试导出到CSV的变量周围创建 PSObject 可能会更好地控制您的输出。请考虑以下内容:

Reading your comments which supplement your question, creating a PSObject around the variables you are trying to export to CSV might give you more control over your output. Consider the following:

$A = "Hello";
$B = "World";

$wrapper = New-Object PSObject -Property @{ FirstColumn = $A; SecondColumn = $B }
Export-Csv -InputObject $wrapper -Path C:\temp\myoutput.txt -NoTypeInformation

使用两列( FirstColumn C:\temp\myoutput.txt $ c>和 SecondColumn )和变量 $ A $ B 放置在第一行

Creates the file C:\temp\myoutput.txt with two columns (FirstColumn and SecondColumn) and the variables $A and $B placed in those columns in the first row

这篇关于Powershell - 将字符串输出为CSV和格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆