Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 918279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:20:55+00:00 2026-05-15T18:20:55+00:00

Note: I’m using ConvertTo-XML and cannot use Export-Clixml : I create a simple PSObjec

  • 0

Note: I’m using ConvertTo-XML and cannot use Export-Clixml:

I create a simple PSObject:

$a = New-Object PSObject -Property @{
    Name='New'
    Server = $null
    Database = $null
    UserName = $null
    Password = $null
}

I then convert it into XML using ConvertTo-XML:

$b = $a | Convertto-XML -NoTypeInformation

The XML looks like this:

<?xml version="1.0"?>
<Objects>
  <Object>
    <Property Name="Password" />
    <Property Name="Name">New</Property>
    <Property Name="Server" />
    <Property Name="UserName" />
    <Property Name="Database" />
  </Object>
</Objects>

I’m having trouble figuring out the dot notation or XPath query to extract the attributes/elements and convert $b back to the original PSObject.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:20:56+00:00Added an answer on May 15, 2026 at 6:20 pm

    You can do this pretty easily with XPath. Although PowerShell usually makes working with XML pretty simple, in this case I think the format using strictly PowerShell syntax would be pretty gross.

    filter XmlProperty([String]$Property) {
        $_.SelectSingleNode("/Objects/Object/Property[@Name='$Property']").InnerText
    }
    
    $Name = $b | Xmlproperty Name
    $Server = $b | XmlProperty Server
    # etc...
    

    EDIT: To generically do this for an XML document that contains one or more Object elements, you can do something like this:

    function ConvertFrom-Xml($XML) {
        foreach ($Object in @($XML.Objects.Object)) {
            $PSObject = New-Object PSObject
            foreach ($Property in @($Object.Property)) {
                $PSObject | Add-Member NoteProperty $Property.Name $Property.InnerText
            }
            $PSObject
        }
    }
    
    ConvertFrom-Xml $b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Note: I am not asking how to use Google Code's SVN repo as a
note: i only want to move 1 shape at a time Circle.prototype.create = function(){
Note: I had another similar question about how to GZIP data using Ruby's zlib
(Note: This post has been edited to show specific use case. See bottom.) I
Note that singleton used in slightly uncommon sense - object visible as single instance
Note: I'm relatively new to MVC3. Input validation seems to be pretty nice with
Note: This question is similar to How to prevent the copy of XML documentation
Note: A closure cannot call any user-defined function, because the function's context is not
NOTE: I am a new user so I'm not allowed to post images nor
NOTE: The scenario is using 2 entity framework models to sync data between 2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.