Overview
This article will give you the basic idea about how to get data from a SharePoint List using Azure HTTP PowerShell Function App with the help of userid and password.
Steps
- If you set up a new Azure Environment, then first we need to install SharePointPnPPowerShellOnline
- Open cloud shell

- Run command “Install-Module -Name SharePointPnPPowerShellOnline”

- Open cloud shell
-
Go to Function App, if function is already Available, we can use the same or we can create a new one. To create a new Function within Function App or new Function App refer here.
- Go to Platform Features of Function App, scroll down and click on Advanced Tools (Kudu)

- Click on Debug console and select CMD

- Select Site ==> wwwroot ==> click on Function Name folder ==> Add new folder [modules] ==> Add new folder [SharePointPnPPowerShellOnline]
Under this folder Upload All PnP PowerShell related files.
Note
You can download package from the below URL
https://www.powershellgallery.com/packages/SharePointPnPPowerShellOnline/3.21.2005.2


- Go to the Function GetData and add the below code.
- using namespace System.Net
- Import-Module D:\home\site\wwwroot\GetData\modules\SharePointPnPPowerShellOnline\Newtonsoft.Json.dll'
- Write-Host "Powershell http trigger"
- $requestBody = Get-Content $req -Raw | ConvertFrom-Json
- $serviceaccount = $env:Userid
- $serviceaccountpassword = $env:Password
- $listname = "[listname]"
- $siteurl = "https://[tenantname].sharepoint.com/sites/[siteurl]"
- $secpassword = ConvertTo-SecureString -String $serviceaccountpassword -AsPlainText -Force
- $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $serviceaccount, $secpassword
- Connect-PnPOnline -Url $siteurl -Credentials $cred
- $web = Get-PnPWeb
- $title = $web.Title
- $listitems = Get-PnPListItem -List $listname
- $listArray = New-Object System.Collections.Generic.List[System.Object]
- foreach ($item in $listitems)
- {
- $listArray.Add([hashtable]@{
- DisplayTitle=$item["Title"];
- Id= $item["ID"]
- }
- )
- }
- $json = $listArray | ConvertTo-Json
- Out-File -Encoding Ascii -FilePath $res -inputObject $json
Note
Please update tenantname, siteurl, listname
- Save and try to run; it will give error because we didn’t specify Environment properties “UserID” & “Password”
- Go to “Platform Features” ==> Configurations

- Click on + New Application Setting

- After adding both Userid & Password the configuration settings will look like below, then click on Save.

- Go to function and click on Run
- Copy Function URL and run in browser, it will return data in JSON format.
Sumamry
Using Azure Function App we can use SharePoint Data to Open source, any HTML or other system.
Note
This code will work if multifactor authentication is not enabled on specified Userid.
If multifactor authentication is enabled then refer to the next blog.

Join the conversation! Your thoughts help the community grow.