I am using PS 5 version and trying to create xml which should look as below:
<ConfigurationItemReport>
<checkListItemCount>14</checkListItemCount>
<checkListItems>
<element>
<checklistItemId>ID_1</checklistItemId>
<checklistItemName>Name1</checklistItemName>
</element>
<element>
<checklistItemId>ID_2</checklistItemId>
<checklistItemName>Name2</checklistItemName>
</element>
....
</checkListItems>
<checkListName>CompCheck</checkListName>
<serverIp>11.113.144.12</serverIp>
</ConfigurationItemReport>
I have written the following powershell 5.0 script so far which is not creating the xml
$allout = @()
$allout += New-Object -TypeName psobject -Property @{
checklistItemName = 'Name1'
}
$output = [ordered]@{
serverHostname = $serverhostname
checkListItems = $allout
}
foreach ($check in $allout) {
$check.checkListItemName
$hash = @{
"Enclosure Model Type" = $check.checkListItemName
}
$obj = New-Object -TypeName psobject -Property $hash
Export-Clixml -Path E:\WindowsOAC\test.xml
}
Export-CliXmlis going to tag it with all kinds of type information intended to be re-imported withImport-CliXml. Do you strictly want the output to be like your example?$object | ConvertTo-Json -Depth [int32]::MaxValue | Out-File -FilePath 'out.json'