Convertto-xml help

Welcome Forums General PowerShell Q&A Convertto-xml help

This topic contains 2 replies, has 2 voices, and was last updated by

3 years, 5 months ago.

  • Author
  • #30952

    Points: 0
    Rank: Member

    I have a custom psobject that a wish to export as un xml file

    $array = @()
            Get-ADGroup -Filter * -SearchBase "$OU,$domain" |
                select-object "distinguishedName","GroupScope","name" | % {
                    $array += New-object  PSObject -Property([ordered]@{"Name"="$($_.Name)";
                                                        "GroupScope" = "$($_.GroupScope)";
                                                        "DistinguishedName" = "$($_.distinguishedName)";
                                                        "Members"="$((Get-ADGroupMember $_.Name | Select-Object Name).Name)"})
                                                        }#end foreach
            $date = get-date -Format yyyyMMdd
            Switch ($ExportType)
                    HTML { $array | ConvertTo-Html -as List | Out-File "$Outfolder\ADGroups-html-$date.html" }
                    XML { $array | ConvertTo-Xml | Out-File "$Outfolder\ADGroups-xml-$date.xml" }
                    CSV { $array | ConvertTo-Csv| Out-File "$Outfolder\ADGroups-csv-$date.csv" }
            }#end switch

    The export works fine with csv and HTML but i can't figure out why its failling with the XML

  • #30954

    Points: 1
    Rank: Member

    Technically ConvertTo-XML is working but in its current usage it is returning an XML document object and only showing the top two properties. You can drill down into the object and see the rest of it. What you are wanting is to view it differently.

    A couple of options. You could specify the -as parameter (string | stream) for your ConverTo-XML cmdlet or you could use Export-CliXML.

  • #30955

    Points: 0
    Rank: Member

    Thanks a lot Curtis, "-as stream" has got me what i wanted, now i just need to go through Don jones book to format my HTML output.

The topic ‘Convertto-xml help’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort