仅在左侧或右侧比较对象 [英] compare-object left or right side only

查看:68
本文介绍了仅在左侧或右侧比较对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速提问

是否有更好的方法(例如,效率更高/更简洁)?

Is there a better (i.e. more efficient / more concise) way to do this?

compare-object $a $b | ?{$_.SideIndicator -eq '<='}

详细信息

比较对象为参数提供 -excludeDifferent -includeEqual 参数,以允许您修改获得的结果.

Compare-Object gives paramenters -excludeDifferent and -includeEqual to allow you to amend which results you get.

  • 同时使用这两种方法可以使您获得内部连接
  • 仅使用 -includeEqual 即可为您提供完整的外部联接
  • 仅使用 -excludeDifferent 是没有意义的;因为默认情况下,相等项被排除在外,所以现在它将排除所有内容.
  • using both gives you an inner join
  • using just -includeEqual gives you a full outer join
  • using just -excludeDifferent is pointless; as by default equal items are excluded, so it will now exclude everything.

没有 -includeLeft -excludeLeft 或类似选项的选项.

There are no options for -includeLeft, -excludeLeft or similar.

当前要做的是左侧为null的外部外部联接(即参考对象中不在差异对象中的项目),我需要按照上面的代码手动过滤结果.

Currently to do a left outer join where the right side is null (i.e. items in the reference object which are not in the difference object) I need to filter the results manually, as per the code above.

我错过了什么吗/有更好的方法吗?

Have I missed something / is there a better way?

http://ss64.com/ps/compare-object.html

推荐答案

没有该cmdlet的选项,但是您可以创建一个过滤器(例如在您的配置文件中),然后使用它来过滤结果:像

there is no option like that for that cmdlet, however you could create a filter (in your profile for example) and then use it to filter the result : something like

filter leftside{
param(
        [Parameter(Position=0, Mandatory=$true,ValueFromPipeline = $true)]
        [ValidateNotNullOrEmpty()]
        [PSCustomObject]
        $obj
    )

    $obj|?{$_.sideindicator -eq '<='}

}

用法

compare-object $a $b | leftside

这篇关于仅在左侧或右侧比较对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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