Questo script in PowerShell 1.0 consente di recuperare informazioni sulle liste utilizzando i Web Service di SharePoint 2007 / 2010 (http://site/_vti_bin/Lists.asmx ).
Dato che utilizza i Web Service, non serve eseguirlo dalle macchine su cui gira SharePoint, si può usare anche da remoto.
L'esempio stampa a video l'elenco di tutte le document library e liste presenti nel sito e poi visualizza i dettagli della lista Calendar. Può tornare utile per recuperare l'ID (guid) della lista necessario per chiamare altri metodi di questo Web Service.

PowerShell

# get info of sharepoint lists
# File: SgartGetListCollection.ps1

$webUrl = "http://192.168.2.70:2010/Site1"
$listUrl ="/Lists/Calendar"
$user = "administrator"
$password = "pass@word1"

#-----------------------------------------------------
# url of WebService
$url = "$webUrl/_vti_bin/lists.asmx"
# method to invoke
$soapMethod = "http://schemas.microsoft.com/sharepoint/soap/GetListCollection"
# soap message to post
$soapMessage = @"
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
     xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetListCollection xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
  </soap:Body>
</soap:Envelope>
"@

$wc = new-object System.Net.WebClient
# set credential
$wc.Credentials = new-object System.Net.NetworkCredential($user, $password)
#$wc.Credentials = [System.Net.CredentialCache]::DefaultCredentials
# set correct header
$wc.Headers.Add("Content-Type", "text/xml;charset='utf-8'")
$wc.Headers.Add("SOAPAction", $soapMethod)
# send POST and get result then cast to XML
$responseLists = [xml]$wc.UploadString($url, "POST", $soapMessage)
$wc.Dispose()

# navigate to xml without xpath
$root = $responseLists.Envelope.Body.GetListCollectionResponse.GetListCollectionResult
#$nodes = $root.Lists.ChildNodes
$nodes = $root.Lists.List

write-host "Lists contents of web $webUrl" -f green
$lists = $nodes | select title, DefaultViewUrl
$lists | format-table

write-host "Detail of $listUrl" -f green
$result = $nodes | ?{ $_.DefaultViewUrl -match "$listUrl/.+\.aspx"}

$result | Format-list

da un risultato simile al seguente

Text

Lists contents of web http://192.168.2.70:2010/Site1

Title                                            DefaultViewUrl
-----                                            --------------
Administrative Report Library                    /AdminReports/Forms/AllItems.aspx
Administrator Tasks                              /Lists/Administrator Tasks/AllItems.aspx
Announcements                                    /Lists/Announcements/AllItems.aspx
Calendar                                         /Lists/Calendar/calendar.aspx
Content Deployment Jobs                          /Lists/Content Deployment Jobs/AllItems.aspx
Content Deployment Paths                         /Lists/Content Deployment Paths/AllItems.aspx
Distribution Groups                              /Lists/Distribution Groups/AllItems.aspx
Health Analyzer Rule Definitions                 /Lists/HealthRules/AllItems.aspx
Job Reports                                      /Lists/Job Reports/AllItems.aspx
List Template Gallery                            /_catalogs/lt/Forms/AllItems.aspx
Master Page Gallery                              /_catalogs/masterpage/Forms/AllItems.aspx
Resources                                        /Lists/Resources/AllItems.aspx
Review problems and solutions                    /Lists/HealthReports/AllItems.aspx
Shared Documents                                 /Shared Documents/Forms/AllItems.aspx
Solution Gallery                                 /_catalogs/solutions/Forms/AllItems.aspx
SSA46670f7cab6a4f05b44c4361c7c87ebb              /Lists/SSA46670f7cab6a4f05b44c4361c7c87ebb/AllItems.aspx
SSA5c78b1490a2744f3b240bb7da0f2ab42              /Lists/SSA5c78b1490a2744f3b240bb7da0f2ab42/AllItems.aspx
SSAedbe9ac43596497ba2109d1d223b8052              /Lists/SSAedbe9ac43596497ba2109d1d223b8052/AllItems.aspx
Style Library                                    /Style Library/Forms/AllItems.aspx
Theme Gallery                                    /_catalogs/theme/Forms/AllItems.aspx
User Information List                            /_catalogs/users/detail.aspx
Web Part Gallery                                 /_catalogs/wp/Forms/AllItems.aspx

Detail of /Lists/Calendar

DocTemplateUrl                :
DefaultViewUrl                : /Lists/Calendar/calendar.aspx
MobileDefaultViewUrl          :
ID                            : {C4D5AEE8-28EE-4EFE-A4DA-A98B1BA204F2}
Title                         : Calendar
Description                   : Use the Calendar list to keep informed of upcoming meetings, deadlines, and other impor
                                tant events.
ImageUrl                      : /_layouts/images/itevent.png
Name                          : {C4D5AEE8-28EE-4EFE-A4DA-A98B1BA204F2}
BaseType                      : 0
FeatureId                     : 00bfea71-ec85-4903-972d-ebe475780106
ServerTemplate                : 106
Created                       : 20100401 08:57:56
Modified                      : 20100401 08:57:56
LastDeleted                   : 20100401 08:57:56
Version                       : 0
Direction                     : none
ThumbnailSize                 :
WebImageWidth                 :
WebImageHeight                :
Flags                         : 541069312
ItemCount                     : 0
AnonymousPermMask             : 0
RootFolder                    :
ReadSecurity                  : 1
WriteSecurity                 : 1
Author                        : 1
EventSinkAssembly             :
EventSinkClass                :
EventSinkData                 :
EmailAlias                    :
WebFullUrl                    : /
WebId                         : 57b2e6d2-9a0d-4865-a964-e8849be8b66d
SendToLocation                :
ScopeId                       : b6f366d0-5112-4e37-b62a-94f543589113
MajorVersionLimit             : 0
MajorWithMinorVersionsLimit   : 0
WorkFlowId                    :
HasUniqueScopes               : False
NoThrottleListOperations      : False
HasRelatedLists               :
AllowDeletion                 : True
AllowMultiResponses           : False
EnableAttachments             : True
EnableModeration              : False
EnableVersioning              : False
HasExternalDataSource         : False
Hidden                        : False
MultipleDataList              : False
Ordered                       : False
ShowUser                      : True
EnablePeopleSelector          : False
EnableResourceSelector        : False
EnableMinorVersion            : False
RequireCheckout               : False
ThrottleListOperations        : False
ExcludeFromOfflineClient      : False
EnableFolderCreation          : False
IrmEnabled                    : False
IsApplicationList             : False
PreserveEmptyValues           : False
StrictTypeCoercion            : False
EnforceDataValidation         : False
MaxItemsPerThrottledOperation : 5000
Questo script permette di vedere:
  • come eseguire una chiamata ad un Web Service costruendo un messaggio soap
  • eseguire un POST ad un sito e recuperare il risultato in XML
  • come gestire in PowerShell i file XML (navigare attraverso i nodi e filtrare)

Vedi anche PowerShell: download di una pagina web
Tags:
PowerShell200 SharePoint498 SharePoint 2007218 SharePoint 2010224 Web service16
Potrebbe interessarti anche: