通过PowerShell Web服务显示SP列表

时间:2015-10-28 16:23:52

标签: powershell sharepoint sharepoint-2010 powershell-ise

我试图检索SP列表中的项目并显示" ows_Title"," ows_Latitude"," ows_Longitude"和" ows_LocationDetails"领域。我通过Web服务访问列表,但我当前的代码不断返回大量XML,我不确定从何处开始。任何帮助将不胜感激。

# Connect to web service
$uri = "http://teams.COMPANY.intranet/_vti_bin/lists.asmx"
$service = New-WebServiceProxy -uri $uri -Namespace SpWs  -UseDefaultCredential 
$service.url = "http://teams.COMPANY.intranet/sites/MYSITE/_vti_bin/lists.asmx"
$xmlDoc = new-object System.Xml.XmlDocument            
$listName = "MapDetails"  
$viewFields = $xmlDoc.CreateElement("ViewFields")
$query = $xmlDoc.CreateElement("Query")          
#$viewfields.InnerXml = "<ViewFields><FieldRef Name='ows_Latitude'></FieldRef><FieldRef Name='ows_Longitude'></FieldRef></ViewFields>"
$list = $service.GetListItems($listname,$null, $null, $viewfields,$null,$null,$null)
$list.outerxml

此输出:

<listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="
#RowsetSchema" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<rs:data ItemCount="2">
   <z:row ows_ID="2" ows_ContentTypeId="0x010094EFD209B7CD4E1AB7F957794F6A99BE00C8C9D25E463F1E4481EDB61A4C0CD8B7" ows_ContentType="MapDetails" ows_Title="UK" ows_Modifie
d="2015-10-28 14:49:58" ows_Created="2015-10-28 10:46:18" ows_Author="14;#Chris Hodgkinson" ows_Editor="88;#Joe Ashworth" ows_owshiddenversion="2" ows_WorkflowVersion="1
" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="UK" ows_LinkTitle="UK" ows_LinkTitle2="UK" ows_Selec
tTitle="2" ows_Order="200.000000000000" ows_GUID="{B0943CAA-A320-43DC-B9E2-ED3D40D35D0C}" ows_FileRef="2;#sites/testcathy/Lists/MapDetails/2_.000" ows_FileDirRef="2;#sit
es/testcathy/Lists/MapDetails" ows_Last_x0020_Modified="2;#2015-10-28 10:46:18" ows_Created_x0020_Date="2;#2015-10-28 10:46:18" ows_FSObjType="2;#0" ows_SortBehavior="2;
#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="2;#2_.000" ows_UniqueId="2;#{DD455D50-6577-43B5-A8A0-6738C5912BCB}" ows_ProgId="2;#" ows_ScopeId="2;#{19293ED2-866
8-4F3C-B8CB-F7D7E8D2A231}" ows__EditMenuTableStart="2_.000" ows__EditMenuTableStart2="2" ows__EditMenuTableEnd="2" ows_LinkFilenameNoMenu="2_.000" ows_LinkFilename="2_.0
00" ows_LinkFilename2="2_.000" ows_ServerUrl="/sites/testcathy/Lists/MapDetails/2_.000" ows_EncodedAbsUrl="http://teams.COMPANY.intranet/sites/testcathy/Lists/MapDetail
s/2_.000" ows_BaseName="2_" ows_MetaInfo="2;#" ows__Level="1" ows__IsCurrentVersion="1" ows_ItemChildCount="2;#0" ows_FolderChildCount="2;#0" ows_Latitude="1.23000000000
000" ows_Longitude="0.560000000000000" ows_LocationDetails="&lt;div&gt;Top united Kingdom Hits&lt;/div&gt;" />
   <z:row ows_ID="3" ows_ContentTypeId="0x010094EFD209B7CD4E1AB7F957794F6A99BE00C8C9D25E463F1E4481EDB61A4C0CD8B7" ows_ContentType="MapDetails" ows_Title="Australia" ows_
Modified="2015-10-28 14:50:19" ows_Created="2015-10-28 12:05:15" ows_Author="14;#Chris Hodgkinson" ows_Editor="88;#Joe Ashworth" ows_owshiddenversion="2" ows_WorkflowVer
sion="1" ows__UIVersion="512" ows__UIVersionString="1.0" ows_Attachments="0" ows__ModerationStatus="0" ows_LinkTitleNoMenu="Australia" ows_LinkTitle="Australia" ows_Link
Title2="Australia" ows_SelectTitle="3" ows_Order="300.000000000000" ows_GUID="{41CD2DF1-9233-4AE2-A978-4E97A33870AC}" ows_FileRef="3;#sites/testcathy/Lists/MapDetails/3_
.000" ows_FileDirRef="3;#sites/testcathy/Lists/MapDetails" ows_Last_x0020_Modified="3;#2015-10-28 12:05:15" ows_Created_x0020_Date="3;#2015-10-28 12:05:15" ows_FSObjType
="3;#0" ows_SortBehavior="3;#0" ows_PermMask="0x7fffffffffffffff" ows_FileLeafRef="3;#3_.000" ows_UniqueId="3;#{3F409B8F-6EC5-45F9-A50D-327830DF3F4C}" ows_ProgId="3;#" o
ws_ScopeId="3;#{19293ED2-8668-4F3C-B8CB-F7D7E8D2A231}" ows__EditMenuTableStart="3_.000" ows__EditMenuTableStart2="3" ows__EditMenuTableEnd="3" ows_LinkFilenameNoMenu="3_
.000" ows_LinkFilename="3_.000" ows_LinkFilename2="3_.000" ows_ServerUrl="/sites/testcathy/Lists/MapDetails/3_.000" ows_EncodedAbsUrl="http://teams.COMPANY.intranet/sit
es/testcathy/Lists/MapDetails/3_.000" ows_BaseName="3_" ows_MetaInfo="3;#" ows__Level="1" ows__IsCurrentVersion="1" ows_ItemChildCount="3;#0" ows_FolderChildCount="3;#0"
 ows_Latitude="0.670000000000000" ows_Longitude="0.450000000000000" ows_LocationDetails="&lt;div&gt;TOP HITS FOR AUS&lt;/div&gt;" />
</rs:data>
</listitems>

如果已经回答了这个问题,请随时指出我正确的方向。

注意:由于此任务的性质,我不能使用CSOM。

1 个答案:

答案 0 :(得分:1)

Powershell具有以友好的方式使用XML的内置功能。使用scanf类型前缀将字符串强制转换为XML对象非常容易,如下所示:

for(i = 0; i < n; i++)
{
    for(j = 0; j < m; j++)
    {
        if(s[i] == x[j])
        {
            s[i] = y[j];
            break;
        }
        if(s[i] == y[j])
        {
            s[i] = x[j];
            break;
        }
    }
}

然后,您可以使用点表示法来访问XML中的元素:

[xml]

在这种情况下,您可以通过访问PS H:\> [xml]$listXml = $list.outerxml 集合中的各个元素来访问各个列表项。

PS H:\> $listXml

    listitems
    ---------
    listitems

PS H:\> $listXml.listitems  

    s     : uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882
    dt    : uuid:C2F41010-65B3-11d1-A29F-00AA00C14882
    rs    : urn:schemas-microsoft-com:rowset
    z     : #RowsetSchema
    xmlns : http://schemas.microsoft.com/sharepoint/soap/
    data  : data

PS H:\> $listXml.listitems.data

     ItemCount        row
     ---------        ---
     2                {z:row, z:row}