Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Formating XML Output

$
0
0

Hello together,

I have an XML-File with a content like this:

<?xml version="1.0" ?>

<objects>

<cn>Share1</cn>

<ownership>

<role type="OWNER" sAMAccountName="Userid_Owner1" />

<role type="DELEGATE" sAMAccountName="Userid_Delegate1" />

</ownership>

<cn>Share2</cn>

<ownership>

<role type="OWNER" sAMAccountName="Userid_Owner2" />

<role type="DELEGATE" sAMAccountName="Userid_Delegate2" />

</ownership>

<cn>Share3</cn>

<ownership>

<role type="OWNER" sAMAccountName="Userid_Owner3" />

<role type="SUPERVISOR" sAMAccountName="Userid_Supervisor3" />

<role type="DELEGATE" sAMAccountName="Userid_Delegate3" />

<role type="DELEGATE" sAMAccountName="Userid_Delegate32" />

</ownership>

<cn>Share4</cn>

<ownership>

<role type="OWNER" sAMAccountName="Userid_Owner4" />

<role type="SUPERVISOR" sAMAccountName="Userid_Supervisor4" />

<role type="DELEGATE" sAMAccountName="Userid_Delegate4" />

</ownership>

<cn>Share5</cn>

<ownership>

<role type="OWNER" sAMAccountName="Userid_Owner5" />

<role type="SUPERVISOR" sAMAccountName="Userid_Supervisor5" />

<role type="DELEGATE" sAMAccountName="Userid_Delegate5" />

</ownership>

</objects>

After getting the content of this XML I get an output of the cn with

$xml.objects.cn

Share1
Share2
Share3
Share4
Share5

An output of the attributes is also possible with

$xml.objects.ownership | %{$_.role} | ft -auto

type       sAMAccountName
----       --------------
OWNER      Userid_Owner1
DELEGATE   Userid_Delegate1
OWNER      Userid_Owner2
DELEGATE   Userid_Delegate2
OWNER      Userid_Owner3
SUPERVISOR Userid_Supervisor3
DELEGATE   Userid_Delegate3
DELEGATE   Userid_Delegate32
OWNER      Userid_Owner4
SUPERVISOR Userid_Supervisor4
DELEGATE   Userid_Delegate4
OWNER      Userid_Owner5
SUPERVISOR Userid_Supervisor5
DELEGATE   Userid_Delegate5

But how can I combine these two outputs.

The best output for me would be in this form:

cn        owner                supervisor               delegate                delegate1            
--------------------------------------------------------------------------------------------------

Share1 Userid_Owner1                                Userid_Delegate1 
Share2 Userid_Owner2                                Userid_Delegate2
Share3 Userid_Owner3 Userid_Supervisor3 Userid_Delegate3 Userid_Delegate32
Share4 Userid_Owner4 Userid_Supervisor4 Userid_Delegate4
Share5 Userid_Owner5 Userid_Supervisor5 Userid_Delegate5

Can you help me to format the xml output like this?

Thanks in advance.

Tina

 

 


Viewing all articles
Browse latest Browse all 8583

Trending Articles