Listing files in SharePoint library without ShareP

2019-06-09 06:44发布

We have a powershell script running on our Exchange server (Exchange 2010/Win 2008 R2) which needs to query a SharePoint document library in SharePoint 2013 to find a file whose name can be different every day. For example,

Stats_2015_10_14_06_00_01.csv or Stats_2015_10_15_06_05_01.csv

This precludes me from being able to hardcode the file name and use the System.Net.WebClient method to download the file locally.

I also don't have the SharePoint module installed on the Exchange server and of course the admin there doesn't want to install it.

I tried converting the HTTPS based sharepoint site name to a UNC (\...) based name but that only seemed to work on my Windows 8 laptop...but failed on the Exchange server.

Any suggestions?

1条回答
孤傲高冷的网名
2楼-- · 2019-06-09 07:19

use the New-WebServiceProxy to make a call to the Lists.asmx webservice.

something like:

$listname = "Documents" 
$query = "<Query>
              <Where>
                 <Lt>
                     <FieldRef Name="ID" />
                     <Value Type="Counter">3</Value>
                 </Lt>
              </Where>
          </Query>"
$queryOptions = ""
$Credentials = Get-Credential
$Ws = New-WebServiceProxy -Uri "Http://mysharepoint.com/mysite/_vti_bin/lists.asmx" -namespace WebServiceProxy -class lists -Credential $Credentials
[xml]$list = $Ws.GetListItems($listName, "", $query, "", 1000, $queryOptions, null)

Reference for Lists.Asmx calls: https://msdn.microsoft.com/en-us/library/office/websvclists.lists.getlistitems.aspx

You now have an object containing the XML of all items in the list (based on your query). you should then be able to traverse that XML data to find your filename then use System.Net.WebClient to download directly because you will now have the path.

alternativly, you might be able to convince your sys admin to let you install the Microsoft.Sharepoint.Dll library into your Exchange server. you can then use powershell to import that and get all the general SP data structures your used to (spsite, Splistitem, etc) without having to install the full Sharepoint Management shell plugin

查看更多
登录 后发表回答