Powershell - Export-CliXml Structure without Nodes

BastiFantasti 6 Reputation points
2020-07-29T07:48:22.69+00:00

Hello,

iam working with PS and WSUS quite some time. I've made a script which automaticaly approves updates.

Within this script i export the approved updates (Title, ID and arrivaltime) via "Export-CliXml" into a XML-File.
14281-right.png

Every now and then, when a new list has to be established, the exported results have no nodes, no structure ..
14174-wrong.png

What am i doing wrong?
How can i export with Nodes?

When i later import the list without structure, i can not handle the information properly.

$List = Import-CliXml PreTest.xml
$List[X][X] <- is not working, i can not iterate through the values anymore

Anyone knows what issue iam facing?

Best regards!

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,205 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. BastiFantasti 6 Reputation points
    2020-07-30T13:46:38.443+00:00

    And here my solution:

    $List = @()            
    $Updates_Pretest =  $WSUS.GetUpdates() | select -First 10
    if ($Updates_Pretest.count -gt 0)            
        {            
        $List = $Updates_Pretest | ForEach {
        [pscustomobject]@{
            ID = $_.Id.UpdateId.Guid
            Ankunftsdatum = (Get-Date -Format "MM.dd.yyyy")
            UpdateTitle = $_.title
            }}
        }
    $List | Export-Clixml -Path ("c:\" + "Test.xml")
    
    1 person found this answer helpful.

  2. Rich Matheisen 45,096 Reputation points
    2020-07-29T15:04:33.65+00:00

    Have you examined the object you're exporting to verify that it has the structure and properties you expect? Nobody knows how you create those objects without you displaying the underlying code in your script.

    0 comments No comments

  3. BastiFantasti 6 Reputation points
    2020-07-30T13:38:50.237+00:00

    If you ever encounter a similiar Problem: if you examine the Data you want to export, you may notice that the data is only a bunch of strings anymore.

    To achieve a structured XML-Export, you have to export objects.

    In my case i piped the Data first into a pscustomobject and can afterwards export them into a CLIXML.

    0 comments No comments

  4. BastiFantasti 6 Reputation points
    2020-07-30T13:39:29.273+00:00

    Old Code example:

    $List = @()            
    $Updates_Pretest =  $WSUS.GetUpdates() | select -First 10
    if ($Updates_Pretest.count -gt 0)            
        {            
            foreach ($Update in $Updates_Pretest)            
                {            
                    $List += @($Update.Id.UpdateId.Guid;(Get-Date -Format "MM.dd.yyyy");$Update.title)
                } 
        }
    $List | Export-Clixml -Path ("c:\" + "Test.xml")
    

  5. 2020-08-05T02:02:41.237+00:00

    Hi,BastiFantasti-2000
    If your problem has been solved, please don't forget to mark it as an answer, so that if a user has a similar problem, you can easily find the best solution to it. :-)
    (And god, I really appreciate Rich a lot, a well-deserved expert)

    0 comments No comments