Compare-GridView



function Compare-GridView
{
    [CmdletBinding()]
     
    Param
    (
        # Reference Object
        [Parameter(Mandatory=$true,
                   Position=0)]
        [ValidateScript({
          if ($_.psbase.count)
            { Throw 'Reference and Difference Objects must be scalar (single object). Arrays or collections not allowed.' }
          else {$true}
          })]

        $ReferenceObject,
 
        # Difference Object
        [Parameter(Mandatory=$true,
                   Position=1)]
        [ValidateScript({
          if ($ReferenceObject.gettype() -ne $_.gettype())
            { Throw 'ReferenceObject and DifferenceObject type mismatch. Objects must be of the same type.' }
          else {$true}
          })]

        $DifferenceObject,
 
        # Show all properties
        [switch]
        $IncludeAllProperties
    )
 
   End
    {
      $grid = 
        foreach ($Property in ($ReferenceObject.psobject.properties).name)
          {
            if (
                 ( $PSBoundParameters.IncludeAllProperties) -or                
                 ( $ReferenceObject.$Property -ne $DifferenceObject.$Property )
                )
              {
                [PSCustomObject]@{
                    Property = $Property
                    ReferenceObject = $ReferenceObject.$Property
                    DifferenceObject = $DifferenceObject.$Property
                   }
              }
          }
 
      $grid | Out-GridView
 
    }
 }
Advertisements

One response to “Compare-GridView

  1. Seems to be really hard to copy and past out of… Regardless, it was worth the effort to add it to my toolset!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s