Windows Vista Forums

export-clixml and compare-object question
  1. #1


    Gaurhoth Guest

    export-clixml and compare-object question

    I'm trying to compare a "living" object with one imported using import-clixml, but compare-object is not seeing them as identical. See code:

    PS ps:\> $g = gwmi -class win32_desktop
    PS ps:\> export-clixml -path desktop.xml -input $g
    PS ps:\> $h = import-clixml desktop.xml
    PS ps:\>
    PS ps:\> compare-object $g $h



    InputObject SideIndicator
    ----------- -------------
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="N... <=
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="N... <=
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="N... <=
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="c... <=
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="S... <=
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="S... <=
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name=".... <=


    My expectation was that Compare-Object would see the $g and $h as the same since $h is just the XML representation of $g written out with export-clixml and reimported with import-clixml. Am I missing something or my understanding of export/import-clixml totally off-base?

    gaurhoth

      My System SpecsSystem Spec

  2. #2


    /\\/\\o\\/\\/ [MVP] Guest

    Re: export-clixml and compare-object question

    I did meet Gaurhoth on IRC (#PowerShell on freenode)
    and answered it there, but the workaround to get all properties ( -property
    parameter does not support wildcards ) might be usefull for more people,
    so I repost it here :

    <mow002> as one is seralized they are different

    <mow002> PoSH>$g | gm
    <mow002> TypeName:
    System.Management.ManagementObject#root\cimv2\Win32_Desktop
    <mow002> PoSH>$h | gm
    <mow002> TypeName:
    Deserialized.System.Management.ManagementObject#root\cimv2\Win32_Desktop

    <mow002> I found this trick to do a check on all properties (-property does
    not support wildcards)
    <mow002> compare-object $g $h -prop ($g |% {"$($_.psbase.properties | select
    name)"})

    Greetings /\/\o\/\/

    "Gaurhoth" <gaurhoth@live.com> wrote in message
    news:%23m9%23Z8FJHHA.3668@TK2MSFTNGP02.phx.gbl...
    I'm trying to compare a "living" object with one imported using
    import-clixml, but compare-object is not seeing them as identical. See code:

    PS ps:\> $g = gwmi -class win32_desktop
    PS ps:\> export-clixml -path desktop.xml -input $g
    PS ps:\> $h = import-clixml desktop.xml
    PS ps:\>
    PS ps:\> compare-object $g $h

    InputObject SideIndicator
    ----------- -------------
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="N... <=
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="N... <=
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    @{__GENUS=2; __CLASS=Win32_Desktop; __SUPERCLA... =>
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="N... <=
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="c... <=
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="S... <=
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name="S... <=
    \\COMPUTERONE\root\cimv2:Win32_Desktop.Name=".... <=


    My expectation was that Compare-Object would see the $g and $h as the same
    since $h is just the XML representation of $g written out with export-clixml
    and reimported with import-clixml. Am I missing something or my
    understanding of export/import-clixml totally off-base?

    gaurhoth


      My System SpecsSystem Spec

export-clixml and compare-object question problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Export-clixml producing weird xml output j-n-b PowerShell 2 30 Mar 2009
Formatting Inline for Export-CliXML Command Brandon Shell PowerShell 14 18 Sep 2007
Export/Import-CliXml oddity Keith Hill PowerShell 1 11 Feb 2007
Export-CliXml/Export-Csv: Change to Export-Object? Alex K. Angelopoulos [MVP] PowerShell 3 04 Jun 2006
Adding canonical aliases for Compare-Object, Measure-Object, New-Object Alex K. Angelopoulos [MVP] PowerShell 2 26 May 2006