• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

export-clixml and compare-object question

G

Gaurhoth

#1
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 Computer

O

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

#2
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 Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)