2016-05-06 17 views

答えて

0

ここでは、SPOからリスト項目を取得する方法を示します。 "" Microsoft.SharePoint.Client.SharePointOnlineCredentials "dllが必要です。

次に、私がSPO用に変更した以下の機能を使用してください。

利点:これは古いPowerShellバージョンでも機能します。 PowerShellの上位レベルのみを対象にしたい場合は、このコードも機能します。オプションでSystem.Net.HttpWebRequestSystem.Net.HttpWebResponseの代わりにInvoke-Webrequestを使用できます。

function Get-ListItems { 
    [CmdletBinding()] 
    PARAM (
     [Parameter(Mandatory=$true)] 
     [String] $URL 
     ) 
    #$URL = Fix-Url $URL 

    $xml = Request-Rest -URL $URL 
    return $xml 
} 

function Request-Rest{  
    [CmdletBinding()] 
    PARAM (
     [Parameter(Mandatory=$true)] 
     [String] $URL, 

     [Parameter(Mandatory=$false)] 
     [Microsoft.SharePoint.Client.SharePointOnlineCredentials] $credentials, 

     [Parameter(Mandatory=$false)] 
     [String] $UserAgent = "PowerShell API Client", 

     [Parameter(Mandatory=$false)] 
     [Switch] $JSON, 

     [Parameter(Mandatory=$false)] 
     [Switch] $Raw 

) 
    #Create a URI instance since the HttpWebRequest.Create Method will escape the URL by default. 
    $URI = New-Object System.Uri($URL,$true) 

    #Create a request object using the URI 
    $request = [System.Net.HttpWebRequest]::Create($URI) 

    #Build up a nice User Agent 
    $request.UserAgent = $( 
     "{0} (PowerShell {1}; .NET CLR {2}; {3})" -f $UserAgent, $(if($Host.Version){$Host.Version}else{"1.0"}), 
     [Environment]::Version, 
     [Environment]::OSVersion.ToString().Replace("Microsoft Windows ", "Win") 
     ) 

    if ($credentials -eq $null) 
    { 
     $request.UseDefaultCredentials = $true 
    } 
    else 
    { 
     $request.Credentials = $credentials 
    } 

    if ($PSBoundParameters.ContainsKey('JSON')) 
    { 
     $request.Accept = "application/json" 
    } 

    $request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f") 
    #$request.Accept = "application/json;odata=verbose" 

    try 
    { 
     [System.Net.HttpWebResponse] $response = [System.Net.HttpWebResponse] $request.GetResponse() 
    } 
    catch 
    { 
     Throw "Exception occurred in $($MyInvocation.MyCommand): `n$($_.Exception.Message)" 
    } 

    $reader = [IO.StreamReader] $response.GetResponseStream() 

    if (($PSBoundParameters.ContainsKey('JSON')) -or ($PSBoundParameters.ContainsKey('Raw'))) 
    { 
     $output = $reader.ReadToEnd() 
    } 
    else 
    { 
     [xml]$output = $reader.ReadToEnd() 
    } 

    $reader.Close() 

    Write-Output $output 

    $response.Close() 
} 
+0

アマン、これは素晴らしいコードです。しかし、私の必要性は、ページを取得することです。レンダリングされたページのHTMLを調べたい –

関連する問題