Reputation: 113
Is it valid to export objects in powershell using Export-clixml and use the .xml file as a backup?
I'm going to do a massive deletion of thousand of MailContacts in my forest and i want to do a backup of all those MailContacts before i delete them
Thanks in advance, O.Z
Upvotes: 0
Views: 560
Reputation: 201902
I would say no because when you read the objects back in, PowerShell doesn't recreate the original MailContact objects. It creates an object of a special type representing only the public data fields of the original object. If you were to execute this:
Start-Process notepad
Get-Process notepad | Export-Clixml notepad.clixml
Stop-Process -name notepad
And then import the clixml file like so and dump it to the screen:
PS> $n = Import-Clixml .\notepad.clixml
PS> $n
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
78 7 1280 5916 96 0.06 32752 notepad
It looks like you have a notepad process running but the Import-CliXml hasn't recreated the Notepad process. And you will notice the deserialized object doesn't have any of the Process methods like Kill() or WaitForExit(). That's because the imported object contains only a snapshot of the original object's data. There is no feasible way to make the normal methods work on an object like this. You can see this by running the imported object through Get-Member:
PS> $n | Get-Member
TypeName: Deserialized.System.Diagnostics.Process
Name MemberType Definition
---- ---------- ----------
GetType Method type GetType()
ToString Method string ToString(), string ToString(string format, System.IFormatProvider for...
Company NoteProperty System.String Company=Microsoft Corporation
CPU NoteProperty System.Double CPU=0.0625
...
Note the type name Deserialized.System.Diagnostics.Process
.
Now this is not to say that you couldn't use the data from these objects to manually reconstruct the MailContacts but I would look for a more direct route. For instance, couldn't you backup the file the MailContacts are contained in - assuming they are stored in a file? Or perhaps there is an API to allow saving contacts to a file?
Upvotes: 1