我对Powershell很新。只用了约2周。Powershell:解析结构化的文本文件并保存到.CSV
我有一个结构类似这样的文件:
Service name: WSDL Service ID: 14234321885 Service resolution path: /gman/wsdlUpdte Serivce endpoints: -------------------------------------------------------------------------------- Service name: DataService Service ID: 419434324305 Service resolution path: /widgetDate_serv/WidgetDateServ Serivce endpoints: http://servername.company.com:1012/widgetDate_serv/WidgetDateServ -------------------------------------------------------------------------------- Service name: SearchService Service ID: 393234543546 Service resolution path: /ProxyServices/SearchService Serivce endpoints: http://servername.company.com:13010/Services/SearchService_5_0 http://servername2.company.com:13010/Services/SearchService_5_0 -------------------------------------------------------------------------------- Service name: Worker Service ID: 14187898547 Service resolution path: /ProxyServices/Worker Serivce endpoints: http://servername.company.com:131009/Services/Worker/v9 --------------------------------------------------------------------------------
我想解析文件,并有服务名称,服务标识,服务解析路径和服务端点(有时包含多个或不值)在个人柱(CSV)。
除了使用Get-Content并遍历文件,我甚至不知道从哪里开始。
任何帮助将不胜感激。 感谢
你必须“硬编码”字段,并没有照顾多个URL的。 – JPBlanc 2012-07-20 15:24:59
谢谢Shay, 我需要做一些修改才能修复一些错误信息,但是现在输出到控制台时效果很好。当我添加“| export-csv test.csv”时,最后一个对象(Endpoints)在实际文件中显示为“System.Object []”。我假设需要对该对象进行某些操作才能使其成为文本?我会开始使用Google,但如果您可以回复,那就太棒了。 – Bill 2012-07-20 15:38:16
谢谢,根据你对另一个网站上其他人的回答计算出来。将最后一行更改为: } | Select-Object Name,Id,ResolutionPath,@ {n =“Endpoints”; e = {[string] :: join(“;”,$ _。Endpoints)}} 再次感谢您! – Bill 2012-07-20 16:01:22