title: How to connect to SharePoint 2013 on-premise using CSOM in PowerShell
body: <p>I am aware that using CSOM in PowerShell we can connect to SharePoint Online from local machine, how can we connect to SharePoint 2013 on-premise using CSOM in PowerShell?</p>
  
  <p>Note: I am using System.Net.NetworkCredential to get username and password for On-Premsie</p>
  
  <p><strong>Used the below script, getting the errors while executing it.</strong></p>
  
  <pre><code>Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
  Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
  
  function OnPremises-Test {
      $siteUrl = "https://&lt;&gt;/"
  
      $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
      $clientContext.Credentials = New-Object System.Net.NetworkCredential("myusername", "password")
  
      $web = $clientContext.Web 
      $clientContext.Load($web) 
      $clientContext.ExecuteQuery()
  
  Write-Host " Current web title is '$($web.Title)', $($web.Url)"
  
  }
  
   OnPremises-Test
  </code></pre>
  
  <p><strong>Below are the errors:</strong></p>
  
  <p><em>Exception calling "ExecuteQuery" with "0" argument(s): "The remote server returned an error: (403) Forbidden."
  At C:\Users\v-krirao\Desktop\test.ps1:17 char:2
  +     $clientContext.ExecuteQuery()
  +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
      + FullyQualifiedErrorId : WebException</em></p>