我可以在不涉及任何SQL Server/数据库的情况下,在Powershell中的对象上使用SQL命令(例如join)吗? [英] Can I use SQL commands (such as join) on objects in powershell, without any SQL server/database involved?

查看:49
本文介绍了我可以在不涉及任何SQL Server/数据库的情况下,在Powershell中的对象上使用SQL命令(例如join)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为免责声明,我不是专业的Powershell脚本编写者,而是更多的脚本小子"级脚本编写者,他的工作和技术支持超出了他的职责范围.:P

As a disclaimer, I'm no professional powershell scripter, but more of a 'script-kiddie' level scripter who was assigned something far outside the scope of his job, tech support. :P

我一直在研究迁移脚本,以将一些真正的旧数据引入新的软件应用程序中.

I've been working on a migration script to bring some really old data into a new software app.

为此,我正在使用以下代码来联接"两个对象(这些对象是从csv文件导入的).由于将数据呈现给我的方式,我不得不针对相当大的数据集多次运行此联接脚本,并且需要很长时间才能完成.

As a part of this, I'm using the following code to 'Join' two objects (which were imported from csv files). Because of the way the data is presented to me, I'm having to run this join script several times, against rather large data sets, and it's taking a very long time to complete.

我正在使用的代码是:

Import-Csv extract-accounts.csv | ForEach-Object -Begin {
    $Jobs = @{}
} -Process {
    $Jobs.Add($_.NAME,$_.ID)
}

Import-Csv Job.csv | ForEach-Object {
    $_ | Add-Member -MemberType NoteProperty -Name ContactID -Value $Jobs."$($_.DisplayName)" -PassThru
} | Export-Csv -NoTypeInformation Joined-AccountJob.csv

我想知道的是,我可以在Powershell中的对象上使用类似SQL的命令来简化和加速该过程吗?或者,我会更好地获取CSV文件,将它们推入SQL数据库(我对此过程一无所知),执行我的联接,然后将它们导出回csv文件吗?

What I'm wondering is, can I use SQL-like commands on objects in powershell to simplify and speed-up this process? Or, would I be better to take the CSV files, push them into an SQL database (I have no knowledge of this process), perform my joins, then export them back out to csv files?

谢谢!

推荐答案

SQL命令,并非完全不正确.虽然我确实找到了一个在此描述了一种实现方法的网站.

SQL Commands, no not exactly. Although I did find a site that described a way to do it here.

http://social.technet.microsoft.com/Forums/windowsserver/zh-CN/e242e1e9-6a8f-4a46-a884-8bd6811b5e35/combining-multiple-csv-files-with-powershell

基本上,它们的描述以及对我来说听起来正确的方法是,将您想要的CSV中的每一列都抓取到一个变量中,然后将它们转储到一个文本文件中,每个变量用逗号分隔.

Basically what they describe, and what sounds like the right way to do it to me, is to grab each column out of the CSVs you want into a variable then dump them into a text file with each variable separated by a comma.

如果这对您不起作用,并且您仍然希望将其纳入SQL,那么本文将介绍通过几种方法将CSV纳入SQL的过程.

If that doesn't work for you and you want to get them into SQL anyway this article describes the process of getting CSVs into SQL through several methods.

查看全文

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