troubleshooting Question

Customizing XML with Powershell

Avatar of Kasper Katzmann
Kasper KatzmannFlag for Denmark asked on
PowershellXML
2 Comments1 Solution218 ViewsLast Modified:
I need to generate an XML file with user data from AD. The customer needs to get the data in a format where the object names are converted from their original names (i.e. Description is coverted to Comment).

This I accomplish with this script
$me    = Get-ADUser `
            -identity b012345 `
            -Properties `
                description, `
                SID,  `
                description,  `
                Name,  `
                samAccountName,  `
                ObjectClass,  `
                Enabled,  `
                PasswordNotRequired,  `
                CannotChangePassword,  `
                PasswordNeverExpires,  `
                LockedOut |
            Select `
                @{Name='Name';Expression={$_.samAccountName}}, 
                @{Name='Full_name';Expression={$_.Name}}, 
                @{Name='Comment';Expression={$_.description}}, 
                @{Name='Id';Expression={$_.SID}}, 
                @{Name='AccountType';Expression={"Normal"}}, 
                @{Name='AccountPropsEnabled';Expression={$_.PasswordNotRequired}}, 
                @{Name='AccountPropsPasswdRequired';Expression={$_.Enabled}}, 
                @{Name='AccountPropsPasswdCantChange';Expression={$_.CannotChangePassword}}, 
                @{Name='AccountPropsPasswdDontExpire';Expression={$_.PasswordNeverExpires}}, 
                @{Name='AccountPropsCurrentlyLockedOut';Expression={$_.LockedOut}}

$meXML = $me | ConvertTo-Xml
$meXML.save("c:\temp\me.xml")

Unfortunately the output doesn't quite meet the customers needs.
This is the output:
<?xml version="1.0"?>
<Objects>
      <Object Type="System.Management.Automation.PSCustomObject">
            <Property Type="System.String" Name="Name">B012345</Property>
            <Property Type="System.String" Name="Full_name">Kasper Katzmann</Property>
            <Property Type="System.String" Name="Comment">pw</Property>
            <Property Type="System.Security.Principal.SecurityIdentifier" Name="Id">S-1-5-21-2105555113-1573851820-874322375-112263</Property>
            <Property Type="System.String" Name="AccountType">Normal</Property>
            <Property Type="System.Boolean" Name="AccountPropsEnabled">False</Property>
            <Property Type="System.Boolean" Name="AccountPropsPasswdRequired">True</Property>
            <Property Type="System.Boolean" Name="AccountPropsPasswdCantChange">False</Property>
            <Property Type="System.Boolean" Name="AccountPropsPasswdDontExpire">False</Property>
            <Property Type="System.Boolean" Name="AccountPropsCurrentlyLockedOut">False</Property>
      </Object>
</Objects>
What the customer really want's is this:
<User>
    <Name>B012345</Name>
    <Full_name>Kasper Katzmann</Full_name>
    <Comment>pw</Comment>
    <Id>S-1-5-21-2105555113-1573851820-874322375-112263</Id>
    <AccountType>Normal</AccountType>
    <AccountPropsEnabled>1</AccountPropsEnabled>
    <AccountPropsLogonScript>1</AccountPropsLogonScript>
    <AccountPropsHomeDirRequired>0</AccountPropsHomeDirRequired>
    <AccountPropsPasswdRequired>1</AccountPropsPasswdRequired>
    <AccountPropsPasswdCantChange>0</AccountPropsPasswdCantChange>
    <AccountPropsPasswdDontExpire>1</AccountPropsPasswdDontExpire>
    <AccountPropsCurrentlyLockedOut>0</AccountPropsCurrentlyLockedOut>
    <GroupIds>50393,513,61866</GroupIds>
</User>
So my primary question is, how do I strip the output to meet the expectations and secondary, how do I convert "True" and "False" to "1" and "0"
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros