title: How do I run PnP Script on Azure Function App
body: <p>I am trying to get a user to run a powershell script through an Azure function. This script is supposed to create a site on SharePoint with some info provided by users. </p>
  
  <p>I created an Azure Function App to run some PowerShell scripts. When I tried to run my code, it returned an error <code>http 502</code> at <code>Connect-PnPOnline</code>
  If I remove <code>Connect-PnPOnline</code>, I get a 200 response. So I am sure that it has to do with <code>Connect-PnPOnline</code> in my script.</p>
  
  <p>I followed the post by @Lee_MSFT  <a href="https://stackoverflow.com/questions/57614980/get-powershell-script-to-run-sharepoint-commands-on-azure">Get PowerShell Script to Run SharePoint Commands on Azure</a>
  and able to import modules.</p>
  
  <pre><code>using namespace System.Net
  
  param (
      [string]$projectnumber,
      [string]$projectname
  )
  
  $site = "https://xxxxx.sharepoint.com/sites/projects"
  
  $projectsite = -join($site, "/", $projectnumber)
  $projecttitle = -join($projectnumber, " ", $projectname)
  
  Connect-PnPOnline -url $site 
  ...
  </code></pre>
  
  <p>I got 500 from <code>Connect-PnPOnline -url $site</code> and a 502 from <code>Connect-PnPOnline -url $site -UseWebLogin</code></p>
  
  <p>Anyone know that why I have 5xx errors while using <code>Connect-PnPOnline</code>?
  Thanks a lot!</p>