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

Similar Threads
Thread Forum
Export-clixml producing weird xml output
I have the following code: $regex = "(\d{3,4})" $query = Get-ChildItem -Recurse | Where-Object {$_.Name -match $regex} | ? {$_.psIsContainer} |...
PowerShell
Formatting Inline for Export-CliXML Command
Two things... First.. you dont want to use select.. use foreach-object $log | foreach-object{$_.Message -replace "'", ""} | export-clixml ...
PowerShell
Export/Import-CliXml oddity
I'm saving out the results of Get-Command like so: gcm -type alias, filter, function, cmdlet | export-clixml > commands.xml I then load that...
PowerShell
Export-Clixml output is inconvenient for viewing
Export-Clixml writes all the data as the only line of text (well, except line breaks in the data). It is inconvenient for viewing of the output...
PowerShell
Testing object arrays using Compare-Object and -contains
I'm having trouble finding a simple scheme for getting all objects which are members of a set B but not also members of another set A. The...
PowerShell
Export-CliXml/Export-Csv: Change to Export-Object?
I'd like to suggest that these two Export cmdlets (and their corresponding importers) be consolidated into Export-Object/Import-Object cmdlets. ...
PowerShell
Adding canonical aliases for Compare-Object, Measure-Object, New-Object
Vote on this, please. :) https://connect.microsoft.com/feedback/ViewFeedback.aspx?SiteID=99&FeedbackID=79879 Of the 9 object cmdlets, 6 have...
PowerShell