Reputation: 23
I'm using PowerShell v3 on a Windows 8 system and can't find any good resources online to explain this problem I'm encountering. I have the following script:
$CIMProperty = Get-CimInstance win32_OperatingSystem
$OS = [PSCustomObject]@{
Caption = $CIMProperty.Caption
InstallDate = $CIMProperty.InstallDate
}
$Asset = [PSCustomObject]@{
Name = "TSZ"
OperatingSystem = $OS
}
$Asset | ConvertTo-Xml
and when I run it I get the following error:
ConvertTo-Xml : Unexpected end of file has occurred. The following elements are not closed: Objects. Line 9, position 12. At C:\Users\Ben\SkyDrive\Documents\Scripting\Inventory\Troubleshooting-Compact.ps1:12 char:10 + $Asset | ConvertTo-Xml + ~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [ConvertTo-Xml], XmlException + FullyQualifiedErrorId : System.Xml.XmlException,Microsoft.PowerShell.Commands.ConvertToXmlCommand
I've done a bunch of testing and found that this only happens when I have more than one property for my $OS object. Defining the typename for each property didn't seem to help. If I use my own arrays of something like $OS = "test","123"
there is no error.
If I set $OS = Get-CimInstance win32_OperatingSystem
there is no error, and using Export-CliXml cmdlet also works. However I'm trying to produce a well-formatted XML
document that needs minimal processing before being displayed in a custom XML viewer.
Upvotes: 2
Views: 2432