名前 Compare-Object 概要 Compares two sets of objects. 構文 Compare-Object [-ReferenceObject] [-DifferenceObject] [-CaseSensitive] [-Culture [ ]] [-ExcludeDifferent] [-IncludeEqual] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable []] [-PassThru] [-Property []] [-SyncWindow []] [] 説明 The Compare-Object cmdlet compares two sets of objects. One set of objects is the "reference set," and the other set is the "difference set." The result of the comparison indicates whether a property value appeared only in the object from the reference set ( indicated by the <= symbol), only in the object from the difference set (indicated by the => symbol) or, if the Incl udeEqual parameter is specified, in both objects (indicated by the == symbol). NOTE: If the reference set or the difference set is null ($null), Compare-Object generates a terminating error. パラメーター -CaseSensitive [] Indicates that comparisons should be case-sensitive. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Culture [] Specifies the culture to use for comparisons. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -DifferenceObject Specifies the objects that are compared to the reference objects. 必須 true 位置 2 既定値 none パイプライン入力を許可する true (ByValue) ワイルドカード文字を許可する false -ExcludeDifferent [] Displays only the characteristics of compared objects that are equal. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -IncludeEqual [] Displays characteristics of compared objects that are equal. By default, only characteristics that differ betwee n the reference and difference objects are displayed. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationAction [] 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationVariable [] 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -PassThru [] Passes the objects that differed to the pipeline. By default, this cmdlet does not generate any output. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Property [] Specifies the properties of the reference and difference objects to compare. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -ReferenceObject Objects used as a reference for comparison. 必須 true 位置 1 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -SyncWindow [] Specifies the number of adjacent objects that Compare-Object inspects while looking for an match in a collection of objects. Compare-Object examines adjacent objects when it doesn't find the object in the same position in a collection. The default value is [Int32]::MaxValue, which means that Compare-Object examines the entire object c ollection. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false このコマンドレットは、次の共通パラメーターをサポートします: Verbose、 Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer, PipelineVariable、および OutVariable。詳細については、 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。 入力 System.Management.Automation.PSObject You can pipe a DifferenceObject object to Compare-Object. 出力 None, or the objects that are different When you use the PassThru parameter, Compare-Object returns the objects that differed. Otherwise, this cmdlet do es not generate any output. -------------------------- EXAMPLE 1 -------------------------- PS C:\>compare-object -referenceobject $(get-content C:\test\testfile1.txt) -differenceobject $(get-content C:\test\ testfile2.txt) This command compares the contents of two text files. It displays only the lines that appear in one file or in the o ther file, not lines that appear in both files. -------------------------- EXAMPLE 2 -------------------------- PS C:\>compare-object -referenceobject $(get-content C:\Test\testfile1.txt) -differenceobject $(get-content C:\Test\ testfile2.txt) -includeequal This command compares each line of content in two text files. It displays all lines of content from both files, indi cating whether each line appears in only Textfile1.txt or Textfile2.txt or whether each line appears in both files. -------------------------- EXAMPLE 3 -------------------------- PS C:\>$processes_before = get-process PS C:\>notepad PS C:\>$processes_after = get-process PS C:\>compare-object -referenceobject $processes_before -differenceobject $processes_after These commands compare two sets of process objects. The first command uses the Get-Process cmdlet to get the processes on the computer. It stores them in the $processes _before variable. The second command starts Notepad. The third command uses the Get-Process cmdlet again and stores the resulting processes in the $processes_after varia ble. The fourth command uses the Compare-Object cmdlet to compare the two sets of process objects. It displaysthe differe nces between them, which include the new instance of Notepad. 関連するリンク Online Version: http://go.microsoft.com/fwlink/p/?linkid=293945 ForEach-Object Group-Object Measure-Object New-Object Select-Object Sort-Object Tee-Object Where-Object