How to export XML from a SQLite query to a file with PowerShell?

旧巷老猫 提交于 2020-12-15 03:36:02

问题


Using Linux, getting started with SQLite, PowerShell and xml, and so this question is in that context. How do I nicely export the results below?

PS /home/nicholas> 
PS /home/nicholas> $Database                                                                        
/home/nicholas/sql/covid.db
PS /home/nicholas> 
PS /home/nicholas> $Query                                                                           
select * from labs limit 3
PS /home/nicholas> 
PS /home/nicholas> Invoke-SqliteQuery -DataSource $Database -Query $Query                           

Date        : 1/23/2020 12:00:00 AM
Region      : BC
New_Tests   : 2
Total_Tests : 2
Positivity  : 0
Turn_Around : 32

Date        : 1/23/2020 12:00:00 AM
Region      : Fraser
New_Tests   : 0
Total_Tests : 0
Positivity  : 0
Turn_Around : 0

Date        : 1/23/2020 12:00:00 AM
Region      : Interior
New_Tests   : 0
Total_Tests : 0
Positivity  : 0
Turn_Around : 0


PS /home/nicholas> 
PS /home/nicholas> $result=Invoke-SqliteQuery -DataSource $Database -Query $Query                   
PS /home/nicholas> 
PS /home/nicholas> ($result | ConvertTo-Xml).Outerxml
<?xml version="1.0" encoding="utf-8"?><Objects><Object Type="System.Management.Automation.PSCustomObject"><Property Name="Date" Type="System.DateTime">1/23/2020 12:00:00 AM</Property><Property Name="Region" Type="System.String">BC</Property><Property Name="New_Tests" Type="System.Double">2</Property><Property Name="Total_Tests" Type="System.Double">2</Property><Property Name="Positivity" Type="System.Double">0</Property><Property Name="Turn_Around" Type="System.Double">32</Property></Object><Object Type="System.Management.Automation.PSCustomObject"><Property Name="Date" Type="System.DateTime">1/23/2020 12:00:00 AM</Property><Property Name="Region" Type="System.String">Fraser</Property><Property Name="New_Tests" Type="System.Double">0</Property><Property Name="Total_Tests" Type="System.Double">0</Property><Property Name="Positivity" Type="System.Double">0</Property><Property Name="Turn_Around" Type="System.Double">0</Property></Object><Object Type="System.Management.Automation.PSCustomObject"><Property Name="Date" Type="System.DateTime">1/23/2020 12:00:00 AM</Property><Property Name="Region" Type="System.String">Interior</Property><Property Name="New_Tests" Type="System.Double">0</Property><Property Name="Total_Tests" Type="System.Double">0</Property><Property Name="Positivity" Type="System.Double">0</Property><Property Name="Turn_Around" Type="System.Double">0</Property></Object></Objects>
PS /home/nicholas> 
PS /home/nicholas> $result | Export-Clixml           

cmdlet Export-Clixml at command pipeline position 1
Supply values for the following parameters:
Path: .
Export-Clixml: Access to the path '/home/nicholas' is denied.
PS /home/nicholas> 

How can I "nicely" export or write to file the above xml?

The data was imported from csv, which might be easier to work with directly.

来源:https://stackoverflow.com/questions/64964516/how-to-export-xml-from-a-sqlite-query-to-a-file-with-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!