在PowerShell中进行内部联接(不使用SQL) [英] Inner Join in PowerShell (without SQL)

查看:95
本文介绍了在PowerShell中进行内部联接(不使用SQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在PowerShell或PowerCLI中使Inner-JoinCross-Join成为东西?

即使我不是PowerCLI/PowerShell的新手,我对它们也有一个基本的了解,但实际上花了2天的时间来弄清楚这一点,无数篇文档和博客都没有用.

我真正想知道的是输入命令后是否

Get-Content File.txt 

并获得:

Output1 or Table1 is

Name: Abc
Group: Bad
Policy: Great

Name: redi
Group: Good 
Policy: MAD

etc. etc.

其中有100多个,而且显然不仅仅是名称,组,策略这3个元素.


Table2/Output2

Name: Abc
Limit: 10
used: 5

Name: redi
Limit: 20
used: 1

etc. etc.

其中

100个.


以及另外13个这些文本文件表,所有这些表的名称"都是唯一的.

如何使用Name和所有其他元素最后将其组合为一个输出?

我最明显的想法是某种类似于加入的东西,即使我一次必须做一次,但即使我不知道该怎么做.

无论如何,PowerShell本身是否都可以执行此操作,而无需使用Python或SQL?

如果是,是否有一种方法可以在无效的位置组合字段?

如果不清楚结果是什么类型,我希望它看起来类似于以下内容:

Name: Abc
Group: Bad
Policy: Great
Limit: 10
used: 5


Name: redi
Group: Good 
Policy: MAD
Limit: 20
used: 1

解决方案

所以我找到了一个更合适的答案,它使用了下面定义的 join-Object 函数:

您可以通过 https://github.com/RamblingCookieMonster访问它/PowerShell/blob/master/Join-Object.ps1

我真正要做的就是将我的输出定义为$ A和$ B和$ C等,然后

$Join1=  Join-Object -Left $A -Right $B -LeftJoinProperty Name - RightJoinProperty Name

先制作$ Join2,然后再制作3个,直到我完成所有任务

$Join2 = Join-Object -Left $Join1 -Right $C -LeftJoinProperty Name -RightJoinProperty Name

$Join3 = Join-Object -Left $Join2 -Right $D -LeftJoinProperty Name -RightJoinProperty Name

$Join4 = Join-Object -Left $Join3 -Right $E -LeftJoinProperty Name -RightJoinProperty Name

直到我完成所有任务

How do we make Inner-Join or something a Cross-Join in PowerShell or PowerCLI?

Even though im new to PowerCLI/PowerShell , I do have a basic grasp on them, yet have practically spent 2 days trying to figure this, going through numerous documentations and blogs to no avail.

All I really want to know is if after typing my command

Get-Content File.txt 

and getting:

Output1 or Table1 is

Name: Abc
Group: Bad
Policy: Great

Name: redi
Group: Good 
Policy: MAD

etc. etc.

100s of these, and obviously more than just the 3 elements of Name, Group, Policy each.


Table2/Output2

Name: Abc
Limit: 10
used: 5

Name: redi
Limit: 20
used: 1

etc. etc.

100s of these.


and like 13 more of these text file tables, all with the "Name" as unique.

How can I combine it into one output at the end using Name with all the other elements?

My most obvious thought was something akin to joins, even if I had to do them 1 at a time, but even that I cant figure out how to do.

Is there anyway to do this in PowerShell itself without me having to go into Python or SQL?

If yes is there a method that is able to combine fields in spots where it's null?

If its not clear what type of result I am hoping for it will look something akin to this:

Name: Abc
Group: Bad
Policy: Great
Limit: 10
used: 5


Name: redi
Group: Good 
Policy: MAD
Limit: 20
used: 1

解决方案

So I found an Answer which was more suitable and it uses the join-Object function which was defined below:

you can access it at https://github.com/RamblingCookieMonster/PowerShell/blob/master/Join-Object.ps1

All I really had to do was Define my outputs as $A and $B and $C and so on, and just

$Join1=  Join-Object -Left $A -Right $B -LeftJoinProperty Name - RightJoinProperty Name

made $Join2 then 3 so on until I got it all done

$Join2 = Join-Object -Left $Join1 -Right $C -LeftJoinProperty Name -RightJoinProperty Name

$Join3 = Join-Object -Left $Join2 -Right $D -LeftJoinProperty Name -RightJoinProperty Name

$Join4 = Join-Object -Left $Join3 -Right $E -LeftJoinProperty Name -RightJoinProperty Name

Until I got it all done

这篇关于在PowerShell中进行内部联接(不使用SQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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