我對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