Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

In Sharepoint there are many OOB list with a field "Xml". For example, by running this:

$url = http://sharepoint.domain.com
 $site = Get-SPSite $url
 $site.rootweb.lists["User Information List"].items[0].xml

I can get the first record's XML field content, which similar to below:

<z:row xmlns:z='#RowsetSchema' ows_Content
                                     TypeId='0x011000BD0F8C58BB1C05479051B0702A
                                     322F4F' ows_Title='Welcome to my blog!' 
                                     ows_Body='&lt;div class=&quot;ExternalClas
                                     sB6FC829583324141B0BCF6104B6D0E23&quot;&gt
                                     ;&lt;p&gt;This is where I&#39;ll be 
                                     sharing my thoughts on topics that matter 
                                     to me. Who knows... I might even share 
                                     pictures, videos and links to other 
                                     interesting stuff.&lt;/p&gt;&lt;p&gt;If I 
                                     catch your interest, let me hear from 
                                     you.&lt;/p&gt;&lt;/div&gt;' 
                                     ows_NumComments='0' ows_PostCategory='' 
                                     ows_CategoryID='' 
                                     ows_PublishedDate='2014-02-05 00:31:41' 
                                     ows_RatedBy='' ows_LikedBy='' ows_ID='1' 
                                     ows_ContentType='Post' 
                                     ows_Modified='2014-02-04 20:31:41' 
                                     ows_Created='2014-02-04 20:31:41' 
                                     ows_Author='1073741823;#System Account' 
                                     ows_Editor='1073741823;#System Account' 
                                     ows_owshiddenversion='1' 
                                     ows_WorkflowVersion='1' 
/>

My question is : 1. What kind of XML is it? Do it has a format name and suggested accessing method? 2. Can I access the value "ows_Author" by powershell?

share|improve this question

2 Answers 2

The XML represents the inherent configuration of a particular list item.

Generally you wouldn't want to access the values by reading/parsing the XML directly, but rather using the wrapper object.

You can access any of those fields using the "array" accessor for the wrapper field value object.

Example: http://www.robertkuzma.com/2012/09/get-items-from-sharepoint-list-using-powershell-script/

share|improve this answer
    
Thank you! I get what I need. But I am not fully understand the syntax. I can get the author value by $_['author'] or $_['ows_author'] but not $_['ows_aut']. Why is it? Any reference for this "wrapper" method? Thanks. –  Mark May 2 at 5:47
    
When you access $site.rootweb.lists["User Information List"].items[0] you get a SPListItem which has the Item property which you can use as $_['fieldname'] to get a fields value from Title, InternalName or StaticName of the field –  Per Jakobsen May 2 at 7:53
    
How can I find out the Title, InternalName or StaticName of the field? –  Mark May 2 at 8:01
    
Title is the fieldname shown in the UI. InternalName is the name after ows_ in the XML. StaticName is the same as InternalName unless it's changed by code. $site.rootweb.lists["User Information List"].Fields will give all the fields with this as attributes. –  Per Jakobsen May 2 at 8:07
    
Thanks. Got it. –  Mark May 2 at 8:54

As @Amadeo answers you should use SPListItem.Item aka. "array" property to get fieldvalues.

But in general if you want to access XML values in PowerShell you just have to cast the string to xml then you can just dot your way through elements and attributes like this:

$url = http://sharepoint.domain.com
$site = Get-SPWeb $url
$xml = [xml]$site.lists["User Information List"].items[0].xml
$xml.row.ows_Author

BTW If you need to access the SPWeb at an URL just use Get-SPWeb instead of Get-SPSite and RootWeb

To get the Id of the User as requested in the comment use something like:

$url = http://sharepoint.domain.com
$web = Get-SPWeb $url
$list = $web.Lists["User Information List"]
$item = $list.Items[0]
$author = New-Object -Type 'Microsoft.SharePoint.SPFieldUserValue' -ArgumentList ($web ,$item["Author"])
$author.LookupId
share|improve this answer
    
Actually I want to get the member ID which match with the ID returned by Get-SPUser. When I call $_['Member'] it returns a string like "33;#Peter Morris". Can I get "33" directly? –  Mark May 2 at 8:26
    
See addition to answer –  Per Jakobsen May 2 at 15:22
    
Thanks I can get the Author ID. However a member's ID may not be the Author ID (e.g. the administrator add the member to site, the author will be the admin) –  Mark May 12 at 5:47
    
Oh I get get the member id by using ArgumentList ($web,$_["ows_Member"]). Thank you! –  Mark May 12 at 5:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.